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.
If the Table-Valued Function returns an Entity Type, the DbContext will fail to deploy using Code-First. I found the root cause of this to be that the Types of the properties were CLR types (Int32, String, Guid, etc.) instead of SQL types (int, nvarchar, uniqueidentifier, etc.). More specifically, in the function called by test, the edmx under StorageModels looked like:
storeReturnParameterRowType = RowType.Create(
modelReturnParameterEntityType.Properties.Select(property =>
{
var typeUsage = TypeUsage.Create(model.ProviderManifest.GetStoreType(property.TypeUsage).EdmType, property.TypeUsage.Facets);
var result = EdmProperty.Create(property.Name, typeUsage);
var propertyNames = new[] { nameof(EdmProperty.Name), nameof(EdmProperty.TypeUsage), nameof(EdmProperty.MetadataProperties) };
result.SetMetadataProperties(property.MetadataProperties.Where(m => !propertyNames.Contains(m.Name)));
return result;
}),
null);
Using this edit, I was able to produced the expected edmx. Overall, I have noticed that all the tests for this project are written against a database loaded from file rather than one generated when running the tests. This seems to be a limitation when testing the application of this library.
@Dixin would you be able to verify and integrate this change? Also, would you consider testing the use
of Code-First deployment with this library?
If the Table-Valued Function returns an Entity Type, the DbContext will fail to deploy using Code-First. I found the root cause of this to be that the Types of the properties were CLR types (Int32, String, Guid, etc.) instead of SQL types (int, nvarchar, uniqueidentifier, etc.). More specifically, in the function
called by test
, the edmx under StorageModels looked like:but should be:
A fix I found for this was to change this section of
Function.GetStoreReturnParameters
in Function.DbModel.cs from:to:
Using this edit, I was able to produced the expected edmx. Overall, I have noticed that all the tests for this project are written against a database loaded from file rather than one generated when running the tests. This seems to be a limitation when testing the application of this library.
@Dixin would you be able to verify and integrate this change? Also, would you consider testing the use of Code-First deployment with this library?