Skip to content

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

@kemsky

Description

@kemsky

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions