question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EF generates 2 EntityTypeMapping items

See original GitHub issue

Hello! Thank you very much for your awesome libraries!

Describe the bug For some entites I have an exception “Sequence contains more than one element.” I use Entity Framework 6.2 and code first. I noticed, that this issue happen, when I use “MapToStoredProcedures” method for the corresponding configuration entity class. But it happens for some tables/classes, and does not happen for others.

To Reproduce I am not sure, how can I reproduce this bug. I even create very simple table and entity class with 2 columns and without relationships. But when I added “MapToStoredProcedures” method, AuditLog.EntityFramework threw an excpetion on “SaveChanges” method call. The source of exception is “GetMappingFragment” method in the EntityKeyHelper class. Then I cloned the source of the libraries and debug this method. It is strange, but when I use “MapToStoredProcedures” method EF generates 2 EntityTypeMapping items for this entity. So I resolve my issue, when change line 112:

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

It is very similar on this issue: https://github.com/thepirat000/Audit.NET/issues/17

Libraries (specify the Audit.NET extensions being used including version):

  • Audit.Net: 14.0.3
  • Audit.EntityFramework: 14.0.3

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ivkarabanovcommented, Jan 31, 2019

I have just cheked the update and it is working perfectly.

1reaction
ivkarabanovcommented, Jan 31, 2019

Thank you very much for quick turn around. Your support is much appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced table mapping - EF Core
EF Core allows to map two or more entities to a single row. This is called table splitting or table sharing. Configuration. To...
Read more >
EF Core 1.0 - Include() generates more than one queries
I am using EF 7.0.0-rc1-final. The following statement generates multiple queries on the server. Is this normal or I am missing something ?...
Read more >
EF Core 7: It Just Keeps Getting Better
This mapping creates a second table with its own PersonId column that's a primary key as well as a foreign key pointing back...
Read more >
Entity Framework (TPT): Part II
Table-per-type inheritance uses a separate table in the database to maintain data and uses a single entity type in the Entity Framework.
Read more >
Entity Framework Performance: 3 Things You Must Consider
How to get the most performance out of Entity Framework. This guide will help you speed up common Entity Framework performance pitfalls.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found