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...). ...
1 vote
2 answers
1k views
Issue with Entity Framework Core: .Include() and .AsNoTracking() not displaying expected related entities
Since upgrading from .NET Framework to .NET Core, I've encountered an unexpected behavior in Entity Framework Core related to the use of .Include() and .AsNoTracking() methods. Consider the following ...
0 votes
1 answer
656 views
Create reusable LINQ Expression
I have a list on SharePoint, where I am trying to load fields for this list like following: var lists = context.Web.Lists; context.Load(lists, n => n.Include(x => x.Title, ...
0 votes
1 answer
815 views
Read object inside object in entity framework from database
Im making a movieshop for school. I have a movie as a domain model, and each of these models has another model, Genre, as a property. Now when i save this to the database, it adds the movie and the ...
1 vote
1 answer
435 views
Querying in Entity Framework, Select Statement within include
I am trying to shape HTTP GET request where entity wall and some of its parent table(User) rows are displayed. I succeded getting the whole parent row, but I am struggling with select statement where ...
1 vote
2 answers
288 views
Retrieve stuff from database in ASP.NET MVC
How do you mix the concepts of ASP.NET MVC and entityframework in a elegant and robust way when it comes to retrieving stuff from the database and visualizing it via the controller and view? The ...
0 votes
0 answers
371 views
Inverse property EF Core code first dosn't work
I want to display list of users with products of every user. So I have this in my classes : public partial class User { public User() { Product = new HashSet<Product>(); } ...
1 vote
1 answer
262 views
EF 6 load nested entities
I have nested entites like example from msdn. var blogs1 = context.Blogs .Include(b => b.Posts.Select(p => p.Comments)) .ToList(); But in my case, ...
2 votes
2 answers
93 views
EagerLoad entity referenced by complex type
I have an entity called Address. An Address contains a complex type, called House. A House contains a reference to its occupants. An Occupant is an entity. public class Address { [key] ...
0 votes
2 answers
222 views
MVC code first approach not fetching data from table using DbContext
I am using the code-First approach of MVC facing the below issue. I have 1 The Admin model which has 2 properties that represent a separate class as shown below respectively. public class Admin ...
0 votes
1 answer
163 views
Repository pattern issue with API controller querying of intermediate table
Here is Repository, in which I created a methods in which I needed the data on the basis of intermediate table. public Task<IEnumerable<DepartmentSchool>> GetAllDepartmentBySchoolIdAsync(...
0 votes
3 answers
121 views
Why are the data relations not working in C#?
I have a project with two tables, Loans and LoanTypes, and as shown below I've set them up with model classes. The problem is in my controller: when I list loans, there is no LoansType for this loan. ...
0 votes
0 answers
128 views
SQL Query to Linq Query Result into complex object
I have SQL Query ready, and that I want its result into a complex SQL object. I want to use Linq to achieve the result. public class VMPackageList { public string PackageName { get; set; } ...
1 vote
0 answers
97 views
C# Add Field aliases with repository
I have the following controller method: public IActionResult Get() { IEnumerable<Hour> _hours = _hourRepository .AllIncluding(h => h.Customer.name, h => h.Payer.name) ...
0 votes
1 answer
44 views
Access child of child, both with 1:M
Trying to get child of child, both with many relationship. So a CarePeriod has many DailyExerciseSets which has many ExerciseTrials. so carePeriod has collection of DailyExerciseSets which has a ...
1 vote
0 answers
36 views
Nested filtering statements in Entity Framework query
As you can see here I have two entities that are linked with each other in two ways. First way is classic many to many by two ICollection and second is by entity GroupRole which specifies role of user ...