重新填充实体框架导航属性
您好,我有一个 MVC 应用程序,我正在从中调用存储过程。我使用存储过程的原因是因为查询非常复杂并且它已经存在,所以我不妨使用它。
它基本上返回给我一个:
IEnumerable<Activity>
这很好。
有许多外键属性之一,例如:
AreaId
on this 被填充。
但是,在我的模型中,我有导航属性:
// Navigation properties
public virtual Area Area { get; set; }
当然不会通过存储过程获取它。
我想知道是否有一种简单的方法来填充这些导航属性。
我相信我听说过一些命令,您可以调用实体来刷新导航属性。
Hi I have an MVC app I'm calling a stored procedure from. The reason I'm using a stored procedure is because the query is quite complex and it already exists so I may as well use it.
It basically returns to me a :
IEnumerable<Activity>
which is good.
There is a one of many foreign key properties like:
AreaId
on this which gets populated.
However in my model I have the navigation property:
// Navigation properties
public virtual Area Area { get; set; }
which of course isn't populated getting it via the stored procedure.
I'm wondering if there is an easy way to get these navigation properties populated.
I believe I have heard of some command you can call on you entity to refresh navigation properties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用它:
但如果您为枚举中的每个实体调用它,它不会有很好的性能,因为它将为您想要加载的每个
Area
执行单独的查询和数据库往返。这是使用存储过程的缺点 - 一旦采用这种方式,您应该有另一个存储过程来加载所有需要的区域。You can use this:
but it will not have nice performance if you call it for every entity in your enumeration because it will do separate query and database roundtrip for every
Area
you want to load. That is disadvantage of using stored procedures - once you go this way you should have another stored procedure to load all needed areas.