EF navigation properties

In the EF, the outer keys are referred to as navigation properties.

In EF core, the default is only when the query search query itself and not to the foreign key table. If you want to make the query results contain foreign key entity, you need to use include ways to get query results contain foreign key entity. Such as

db.StudentDetails.Include(o=>o.Student).Where(s => s.u_SID == 1).FirstOrDefault().Student.Name;

Sql statement is generated using Include inner jion connection query in the sql, you can query to the foreign key table Student.

 

If you are using the select statement, when used in a foreign key attribute is automatically generated inner join statement, you can query to the foreign key. The following statements can also query the data to the foreign key table.

db.StudentDetails.Where(s => s.u_SID == 1).Select(s => new { aId = s.u_SID, aName = s.Student.s_Name }).ToList();

 

Guess you like

Origin www.cnblogs.com/dayang12525/p/10977621.html