Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackOverflow with self-referencing entities #45

Open
mpartipilo opened this issue Dec 7, 2017 · 2 comments
Open

StackOverflow with self-referencing entities #45

mpartipilo opened this issue Dec 7, 2017 · 2 comments

Comments

@mpartipilo
Copy link

An entity like this will cause a StackOverflow.

    public class Project
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

        public Guid? ParentId { get; set; }
        public Project Parent { get; set; }

        public ICollection<Project> Children { get; set; }
}
@mpartipilo
Copy link
Author

I may have found the problem:
Namespace is compared to other.Name.

        public bool Equals(ClrType other)
        {
            return other is ClrType
                && Name == other.Name
                && Namespace == other.Name
                && Assembly == other.Assembly
                && GenericTypeArguments.Count() == other.GenericTypeArguments.Count()
                && GenericTypeArguments.All(e => other.GenericTypeArguments.Any(ee => e.Equals(ee)));
        }


        public bool Equals(Type other)
        {
            return other is Type
                && Name == other.Name
                && Namespace == other.Name
                && Assembly == other.AssemblyQualifiedName
                && GenericTypeArguments.Count() == other.GenericTypeArguments.Length
                && GenericTypeArguments.All(e => other.GenericTypeArguments.Any(ee => e.Equals(ee)));
        }

Now, next challenge: Newtonsoft.Json.JsonSerializationException: 'Self referencing loop detected for property 'principalEntity' with type 'EntityFrameworkCore.Diagrams.Dto.DbEntity'. Path 'entities[0].foreignKeys[0]'.'

@mpartipilo
Copy link
Author

I think I will just refactor my entities to get rid of the self reference via an external entity. I might do a PR for the .Equals fix, but feel free to do it yourself if I don't make it in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant