Dixin / EntityFramework.Functions

EntityFramework.Functions library implements Entity Framework code first support for stored procedures (with single result type, multiple result types, output parameter), table-valued functions (returning entity type, complex type), scalar-valued functions (composable, non-composable), aggregate functions, built-in functions, niladic functions, and model defined functions.
https://weblogs.asp.net/Dixin/EntityFramework.Functions
MIT License
79 stars 27 forks source link

Exception during migration if entity returned by TVF contains property with ConcurrencyMode #12

Open Daniel-Svensson opened 8 years ago

Daniel-Svensson commented 8 years ago

If an entity returned by a TVF uses optimistic concurrency (such as rowversion) and has ConcurrencyMode Fixed enabled then migrations will fail.

The current code genates a ConcurrencyMode attribute in the storage model for the for the "row type" of the functions. However the ConcurrencyMode is not allowed in that location causing the EdmDiffer to fail

Example of generated Edmx with this problem.

<CollectionType>
              <RowType>
                <Property Name="Id" Type="Int32" Nullable="false" p10:StoreGeneratedPattern="Identity" xmlns:p10="http://schemas.microsoft.com/ado/2009/02/edm/annotation" />
                <Property Name="ParentId" Type="Int32" Nullable="true" />
                <Property Name="Name" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="true" />
                <Property Name="Description" Type="String" MaxLength="2000" FixedLength="false" Unicode="true" Nullable="true" />
                <Property Name="Version" Type="Binary" ConcurrencyMode="Fixed" MaxLength="8" FixedLength="true" Nullable="false" p10:StoreGeneratedPattern="Computed" xmlns:p10="http://schemas.microsoft.com/ado/2009/02/edm/annotation" />
              </RowType>

Proposed fix:

Remove the copying of the ConcurrencyMode data when creating the properties for the row. Even if clone.ConcurrencyMode = property.ConcurrencyMode; is removed from the EdmPropertyExtensions.Clone it seems like the items are copied from parameter.TypeUsage when the new parameter is created but it may be possible to exclude the Facet in some way