Last post Sep 29, 2014 04:38 AM by Kevin Shen - MSFT
Sep 09, 2014 02:08 PM|Mason240|LINK
I have an EF data model where almost all of the tables are set up with a PK of a GUID named Id, and a datetime2 named TimeCreated. Both have defaults of NEWID() and GETDATE() respectively.
When using EF to create new rows, we had a problem where our fields with default values where not getting properly populated in the database.
To fix this I found that I need to set the property StoreGeneratedPattern=Identity for each field in the .edmx gui.
This is time consuming and has to be done everytime a table is updated in the model.
Is there anyway to automate this programicly to just alter the XML elements to add in the property?
<Property Name="Id" Type="uniqueidentifier" Nullable="false" />
<Property Name="TimeCreated" Type="datetime2" Precision="7" Nullable="false" />
<Property Name="Id" Type="uniqueidentifier" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="TimeCreated" Type="datetime2" Precision="7" Nullable="false" StoreGeneratedPattern="Identity" />
Sep 10, 2014 04:29 AM|PatriceSc|LINK
I would just edit the XML file and would use search/replace (on the EDMX file choose "open with" and the XML text editor).
Sep 29, 2014 04:38 AM|Kevin Shen - MSFT|LINK
have you solved your issue?
as far as I know, the property StoreGeneratedPattern is readonly in the edmx file.
so you have to modify the edmx file to add the property.