We recently had a problem where our fields with default values where not getting properly populated in the database during row creation. This can occur when the EDMX model is created in the designer and the default fields do not have their StoreGeneratedPattern property set to Computed or Identity.
Easy enough to fix, simply open the model in the VS designer, select the field, open the properties view and make the required changes.
However we have also seen a problem where these fields are still not getting set correctly even after this change has been applied. Looking into the EDMX model within an XML view we can see that in some cases the StoreGeneratedPattern=Computed property has been retained on the Entity, but removed from the EntitySet, for example:
Entity: Product
<entitytype name="Product"> <key> <propertyref name="ProductId" /> </key> <property name="ProductId" type="Int32" nullable="false"></property> <property name="ProductDescription" type="String" maxlength="30" fixedlength="false" unicode="false"></property> <property name="ProductType" type="String" maxlength="1" fixedlength="true" unicode="false"></property> <property name="EntityRowID" type="Guid" nullable="false" annotation:storegeneratedpattern="Computed"></property> <property name="EntityLastUpdated" type="DateTime" nullable="false" annotation:storegeneratedpattern="Computed"></property> <property name="EntityIsDeleted" type="Boolean" nullable="false" annotation:storegeneratedpattern="Computed"></property> </entitytype>
EntitySet: Products
The StoreGeneratedPattern has gone missing 😦
<entitytype name="Products"> <key> <propertyref name="ProductId" /> </key> <property name="ProductId" nullable="false" type="Int32"></property> <property name="ProductDescription" type="String" unicode="false" fixedlength="false" maxlength="30"></property> <property name="ProductType" type="String" unicode="false" fixedlength="true" maxlength="1"></property> <property name="EntityRowID" nullable="false" type="Guid"></property> <property name="EntityLastUpdated" nullable="false" type="DateTime"></property> <property name="EntityIsDeleted" nullable="false" type="Boolean"></property> </entitytype>
This has occurred on a lot of tables, and we don’t know how or why that has crept in. To fix this we have had to manually fix up the XML file for the EntitySets effected:
<entitytype name="Products"> <key> <propertyref name="ProductId" /> </key> <property name="ProductId" nullable="false" type="Int32"></property> <property name="ProductDescription" type="String" unicode="false" fixedlength="false" maxlength="30"></property> <property name="ProductType" type="String" unicode="false" fixedlength="true" maxlength="1"></property> <property name="EntityRowID" nullable="false" type="Guid" storegeneratedpattern="Computed"></property> <property name="EntityLastUpdated" nullable="false" type="DateTime" storegeneratedpattern="Computed"></property> <property name="EntityIsDeleted" nullable="false" type="Boolean" storegeneratedpattern="Computed"></property> </entitytype>
Leave a Reply