Get with Include fails with multiple related entities
See original GitHub issueI’m having trouble getting your example code to work from the wiki under the ‘Joins’ section. I’ve created the relevant database objects, etc. I have a single workstation that has multiple employee’s. However, when executing the following code:
con.Get(new Workstation {WorkstationId = workStationId },
statement => statement.Include<Employee>()));
An exception is thrown:
Sequence contains more than one element
Stack trace if useful:
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at Dapper.FastCrud.SqlStatements.RelationshipSqlStatements`1.SelectById(IDbConnection connection, TEntity keyEntity, AggregatedSqlStatementOptions`1 statementOptions)
at DapperCore.Repository.Repository.GetWorkstation(Int32 workStationId) in C:\W\DapperCore\DapperCore\src\DapperCore\Repository\Repository.cs:line 28
at DapperConsole.Program.Main(String[] args) in C:\W\DapperCore\DapperCore\src\DapperConsole\Program.cs:line 23
It doesn’t seem to be able to handle the fact that the Workstation
has many Employee
objects associated with it.
If I remove the Employee’s from the database so that there is only a one-to-one relationship between the two. The code above works fine and I get only a single Employee
object in the collection.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Entity Framework Include() is not working
I am getting a null reference exception when I access the QuestionType property. I am using Include("QuestionType") but it doesn't appear to be ......
Read more >Performance issue when using multiple includes and ...
I'm having a performance issue when using multiple includes with SplitQuery and QueryFilters. When I do: dbContext.Principal .Include(p => p.
Read more >Loading Related Entities - EF6
Include is an extension method in the System.Data.Entity namespace so make sure you are using that namespace. Eagerly loading multiple levels.
Read more >Querying in Entity Framework Core
Use the Include() method multiple times to load multiple navigation properties of the same entity. For example, the following code loads Grade and ......
Read more >Querying data via the DbSet
The Include method is used to specify related entities that should be included in the query so that you don't have to issue...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I believe I found the problem. The algorithm is creating unique entities but this information should also be used later on as Dapper still returns an entity per row. The fix should be trivial and it will be faster than simply applying
Distinct
.Fixed and released. Give it a shot but be aware that Dapper is suffering from a bug that causes the async methods to fail.