Bug with .ssdl generation

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
strandedpirate
Posts: 21
Joined: Tue 07 Jan 2014 12:38

Bug with .ssdl generation

Post by strandedpirate » Thu 09 Apr 2015 23:17

There is a bug with how the .ssdl is generated. When a property of type uniqueidentifier has its Store Generate Pattern set to Identity the .ssdl does not get generated with a StoreGeneratedPattern="Identity" for said property.

This is a big problem because the .ssdl file is one of three that is included as meta-data and used by the Entity Framework to map things out. The net result of this bug is that the Entity Framework will not know that this particular property is supposed to get its value from the server and instead will attempt to provide the value from the client which in the case of a Guid winds up being '00000000-0000-0000-0000-000000000000' and you get a "Violation of PRIMARY KEY constraint" exception.

Here's an example of the .ssdl generated that has a property who's Store Generate Pattern set to Identity but is missing the StoreGeneratedPattern="Identity" in the output. If I manually add this to the .ssdl the "Violation of PRIMARY KEY constraint" exception goes away and Entity Framework once again knows that this property is supposed to get its value from the server.

Code: Select all

 <EntityType Name="AnonymousUser">
    <Key>
      <PropertyRef Name="UserId" />
    </Key>
    <Property Name="UserId" Type="uniqueidentifier" Nullable="false" devart:DefaultValue="newsequentialid()" />
    <Property Name="LastVisited" Type="datetime2" Nullable="false" devart:DefaultValue="sysutcdatetime()" />
    <Property Name="CreatedOn" Type="datetime2" Nullable="false" devart:DefaultValue="sysutcdatetime()" />
    <Property Name="IpAddress" Type="nvarchar" Nullable="false" MaxLength="50" />
  </EntityType>

Code: Select all

static string GetConnectionString()
{
	var connectionBuilder = new SqlConnectionStringBuilder();
	connectionBuilder.UserID = AppSettings.Instance.ConnectionSettings.DbUserName;
	connectionBuilder.Password = AppSettings.Instance.ConnectionSettings.DbPassword;
	connectionBuilder.InitialCatalog = AppSettings.Instance.ConnectionSettings.DbName;
	connectionBuilder.DataSource = AppSettings.Instance.ConnectionSettings.Server;

	EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder();
	ecsb.Provider = "System.Data.SqlClient";
	ecsb.ProviderConnectionString = connectionBuilder.ConnectionString;
	ecsb.Metadata = GetMetaData();
	return ecsb.ConnectionString;
}

static string GetMetaData()
{
	var modelPrefix = "MyApp.Data.Models.MyContext";

	var metaData = new StringBuilder();
	metaData.Append("res://*/" + modelPrefix + ".csdl|");
	metaData.Append("res://*/" + modelPrefix + ".ssdl|");
	metaData.Append("res://*/" + modelPrefix + ".msl");

	return metaData.ToString();
}

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

Re: Bug with .ssdl generation

Post by Shalex » Mon 13 Apr 2015 15:04

I cannot reproduce the problem with the latest (5.7.586) build of Entity Developer.

Please make sure that you set "Store Generate Pattern=Identity" for the property in the SSDL (Store) part of the model. For this, navigate to Tools > Entity Developer > Model Explorer > *.Store > Tables/Views > %TableName% > %PropertyName% and press F4 (Properties).

If this doesn't help, send us a test model for reproducing the issue. You are using a predefined DbContext template, aren't you?

strandedpirate
Posts: 21
Joined: Tue 07 Jan 2014 12:38

Re: Bug with .ssdl generation

Post by strandedpirate » Sat 18 Apr 2015 18:45

Ok, that fixed it. Does ED determine what a column's Store Generated pattern is supposed to be or is it simply obtaining this information from a Microsoft assembly?

Any reason the logic couldn't be changed so that columns who are a primary key and have a default value are defaulted to an Identity store generated pattern?

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

Re: Bug with .ssdl generation

Post by Shalex » Mon 20 Apr 2015 12:12

If you are using the Model First approach and the Model Settings > Synchronization > Mapping > "Enable automatic synchronization of storage part and mapping of the model with its conceptual part" option is turned on, "Store Generate Pattern=Identity" in CSDL will set "Store Generate Pattern=Identity" in SSDL as well automatically.

Post Reply