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

Multiple EntityTypeMapping elements in EDMX #17

Closed
fire-birdie opened this issue Dec 8, 2016 · 2 comments
Closed

Multiple EntityTypeMapping elements in EDMX #17

fire-birdie opened this issue Dec 8, 2016 · 2 comments
Assignees

Comments

@fire-birdie
Copy link

Hi, and let me start by saying thanks for the awesome project.

I recently integrated Audit.EntityFramework into an existing project that uses an EDMX file. It worked perfectly, except for one entity that is mapped to modification functions. After some digging, I discovered that the designer had created two EntityTypeMapping elements for the entity, one containing the MappingFragment, and the other containing the ModificationFunctionMapping. This appears to be perfectly valid inside the various EF components, but results in an InvalidOperationException ("Sequence contains more than one element.") on line 161 of EntityKeyHelper.cs.

I've managed to get around the error by merging the two EntityTypeMapping elements in the EDMX, but since the designer has a mind of it's own, I wouldn't be surprised if it puts things back to the way they were the next time the file is updated from the database.

I noticed that, at runtime, EF had merged the function mapping metadata into the EntityTypeMapping instance that contained the fragment, however the opposite was not true, so it might be possible to prevent the error by filtering out EntityTypeMapping instances that don't contain any fragments. i.e. Line 161 could be updated to:

            .EntityTypeMappings.Single(m => m.Fragments.Count != 0)

Regards
Rory

@thepirat000
Copy link
Owner

Thanks for your comments!

This was fixed on v4.7 as your suggestion.

Regards

@fire-birdie
Copy link
Author

Happy to help, thanks for the quick response.

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

2 participants