[英]EF SqlQuery with navigation properties
I want call sp in t-sql from EF 6. At the same time i want load data to navigation property. 我想从EF 6在t-sql中调用sp。同时,我想将数据加载到导航属性。 On sql server side my SP Joins 2 table and returns.
在sql服务器端,我的SP加入2表并返回。 But EF side dont bind navigation properties.
但是EF方面不绑定导航属性。
My query code loads car data but when i want reach Engine.Name it comes null. 我的查询代码加载了汽车数据,但是当我想到达Engine.Name时,它变为null。 How can i fill it ?
我该如何填充?
//query code
_context.Cars.SqlQuery("select * from Car join Engine on Cars.EngineID = Engine.EngineID")
//sample code
public class Car
{
public int ID { get; set; }
public string Name { get; set; }
public int EngineID { get; set; }
public virtual Engine CarEngine { get; set; }
}
public class Engine
{
public int EngineID { get; set; }
public string Name { get; set; }
}
Take a look at these questions: 看一下这些问题:
Entity Framework - Eagerly load object graph using stored procedures 实体框架-使用存储过程急于加载对象图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.