Linked Questions
31 questions linked to/from Entity framework linq query Include() multiple children entities
202 votes
7 answers
268k views
EF LINQ include multiple and nested entities
Ok, I have tri-leveled entities with the following hierarchy: Course -> Module -> Chapter Here was the original EF LINQ statement: Course course = db.Courses .Include(i => i....
87 votes
5 answers
57k views
Entity Framework - Is there a way to automatically eager-load child entities without Include()?
Is there a way to decorate your POCO classes to automatically eager-load child entities without having to use Include() every time you load them? Say I have a Class Car, with Complex-typed ...
51 votes
6 answers
71k views
A specified Include path is not valid. The EntityType does not declare a navigation property with the name *
I'm trying to get data from a LocalDb into my MVC Controller. I tried this: UsersContext db = new UsersContext(); var users = db.UserProfiles.Where(u => u.UserId == WebSecurity.CurrentUserId) ...
67 votes
2 answers
34k views
Select multiple nested levels of child tables in Entity Framework Core
I want to get multiple nested levels of child tables in Entity Framework Core using eager loading. I don't think lazy loading is implemented yet. I found an answer for EF6. var company = context....
46 votes
3 answers
74k views
How do you construct a LINQ to Entities query to load child objects directly, instead of calling a Reference property or Load()
I'm new to using LINQ to Entities (or Entity Framework whatever they're calling it) and I'm writing a lot of code like this: var item = (from InventoryItem item in db.Inventory where item....
42 votes
1 answer
47k views
Using EF Core ThenInclude() on Junction tables
I'm transfering my .NET Framework (EF6) code to ASP.NET Core (EF Core), and I stumbled upon this issue. Here is some example code: In EF6 I use Include() and Select() for eager-loading: return ...
2 votes
1 answer
5k views
entityframework core - many to many - The property expression is not valid
Application Version: Asp Net Core 1.1 EF: Microsoft.EntityFrameworkCore (1.1.1) Line: _dbContext.MyTable1.Include(c => c.MyIntermediateTable).ThenInclude(k => k.Select(x => x.MyTable2)).ToList(); ...
0 votes
2 answers
3k views
How to get Country Name based on its Id in Entity framework using Mvc?You can just have a look at the following things
The above is my database .I have for tables Contact,Countries,States,Cities.The Country in contact table is foreign key to the Id in countries table. And I am using entity framework to get the data.I ...
0 votes
1 answer
4k views
Entity Framework Related Tables Get and Save Data
I have been searching the NET and SO for some answers - I am pretty much a noob to Entity framework .. so I do have some confusion on related entities .. I am using C# , Winforms, Linq , EF6^ (...
3 votes
2 answers
2k views
Entity Framework Core not loading related data from reference table
MY Model M:M relationship Reference to https://www.entityframeworktutorial.net/efcore/configure-many-to-many-relationship-in-ef-core.aspx Models public class Post { [Key] public int Id { get; ...
4 votes
1 answer
1k views
EntityFramework: Eager loading with excludes instead of includes?
My data model has a lot of nested entities and I would like to eagerly load the whole object tree ... except for a view entities that will be explicitly loaded on demand. Using include paths I have ...
1 vote
2 answers
1k views
Class with multiple List Properties of same type but with different restrictions
Here's my problem: I have a class that have 2 list properties of the same class type (but with some different restriction as on how to be filled), let's say: public class Team { [Key] ...
2 votes
0 answers
2k views
Entity Framework: Load related objects/tables
I'm using Entity Framework to save my data to a database. Now I have a class: public class User { public int Id { get; set; } public virtual ICollection<User> Friends { get; set; } ...
1 vote
2 answers
732 views
Check if user exists and return user + roles EF6
I'm trying to figure out how can i retrieve roles with Any and check if user exists on the same query and return as SingleOrDefault() but doesn't seem to work. private User Authenticate(...
0 votes
1 answer
1k views
Entity Framework Core : DbContext not linking entities
I'm trying to use ASP.NET Core 2.2.0 with Entity Framework Core and I'm facing a bit of troubles. I want to display a list of pictures of different celestial objects I took (nebula, galaxies, etc...). ...