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

Migration breaks with Owned Entity Types #2

jsancho opened this issue Jan 7, 2019 · 4 comments


None yet
2 participants
Copy link

commented Jan 7, 2019


When creating a new migration that uses owned entity types, it will internally crash with an error similar to

(The entity type 'NameOfOwnedEntity' cannot be added to the model because a weak entity type with the same name already exists.

It's taken me a bit of time to narrow it down the issue to this extension because I was wrongly assuming that it had to do with our non-standard EF core configuration.

Anyway, I have added a simple way to reproduce the issue in my own fork

It consists in a simple Address class that becomes an owned type of Person.
After adding it, both tests in the project will fail to execute with the following error

Message: System.AggregateException : One or more errors occurred. (The entity type 'Address' cannot be added to the model because a dependent entity type with the same name already exists

The hacky workaround that I'm currently using is to skip owned types in the AttributedIndexBuilderExtension selector

//var entityTypes = modelBuilder.Model.GetEntityTypes();
var entityTypes = modelBuilder.Model.GetEntityTypes().Where(et => et.DefiningEntityType == null);

This makes the tests succeed, but it results in ignoring any [Index] flags that might have been added to the owned type itself.
Ideally, we would want to be able to add indexes to any column of the entity.

I'd love to come up with a PR that adds support for owned types, but I'm really struggling for time at the moment.
So I thought I might as well give you a heads up in case you can investigate this issue further, or have any hints to share on how to go about solving the issue.

By the way, thanks very much for creating this library in the first place. It's been so helpful! :)


This comment has been minimized.

Copy link

commented Jan 18, 2019

@jsancho Thank you for your reporting!

I tried to resolve this issue, at the feature/owned-types-support branch.

It looks working fine for me. (See also results of unit test on AppVayor.)

I would like to release the new version that will be merged from the feature/owned-types-support branch after few days, if there are no more problems.


This comment has been minimized.

Copy link

commented Jan 18, 2019

I published beta release just now.

You can try this package if you prefer.


This comment has been minimized.

Copy link

commented Jan 18, 2019


It's not only a matter of fixing the previous crash, but you've also added full support for the [Index] attribute within Owned Types.

I've reintroduced the nuget package in our project, and it's all worked right away.

Thanks so much for your help, very impressed with your effort! 🥇


This comment has been minimized.

Copy link

commented Jan 22, 2019

I published the package of release build.

Thank you for your contribution, @jsancho ! 👍

@jsakamoto jsakamoto closed this Jan 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.