EntityFramework.Functions
EntityFramework.Functions copied to clipboard
The order of Function elements is not deterministic on .NET Core
The issue is rare, but still possible. Migrations fail with message that there are pending changes when in fact everything is OK.
The following code is problematic:
public static void AddFunctions(this DbModel model, Type functionsType)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (functionsType == null)
{
throw new ArgumentNullException(nameof(functionsType));
}
functionsType
.GetMethods(BindingFlags.Public | BindingFlags.InvokeMethod
| BindingFlags.Instance | BindingFlags.Static)
.Select(methodInfo => new
{
MethodInfo = methodInfo,
FunctionAttribute = methodInfo.GetCustomAttribute<FunctionAttribute>()
})
.Where(method => method.FunctionAttribute != null)
.ForEach(method => model.AddFunction(method.MethodInfo, method.FunctionAttribute)); // <= must be ordered
}
There is no order, so EDMX xml may include <Function> tags in different order and as a result deep equality check fails inside EF6.