简体   繁体   English

具有导航属性的EF SqlQuery

[英]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; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM