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

The order of Function elements is not deterministic on .NET Core #45

Open kemsky opened 2 years ago

kemsky commented 2 years ago

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.