在实体框架使用存储过程,我怎么得到有填充其导航性能的实体? [英] Using a stored procedure in entity framework, how do I get the the entity to have its navigation properties populated?

查看:149
本文介绍了在实体框架使用存储过程,我怎么得到有填充其导航性能的实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实体框架是几近极限速度慢,所以我试图用一个存储过程,但我遇到了这个问题。

Entity framework is cripplingly slow so I tried using a stored procedure but I ran into this problem.

实体框架允许你定义产生一个实体的存储过程。但是我的实体有使用这种方法时,它没有被填充导航属性。

Entity Framework allows you to define a stored procedure that produces an entity. However my entity has 'navigation properties' which are not being populated when using this method.

有没有一种解决办法?

推荐答案

那么存储过程是不是组合的。因此,有没有办法自动拨打您的存储过程,并有EF填充关系在同一查询,使用include()或东西。

Well stored procedures are not composable. So there is no way to call your SPROC and have the EF automatically populate relationships in the same query, using Include() or something.

所以说你的产品和类别

和你有一个存储过程,以获得产品:

and you have a sproc to get Products:

var products = context.GetProducts(someproductfilter);

所产生的产品会不会有自己的类加载。

the resulting products won't have their categories loaded.

不过,如果您有第二个存储过程,获取类别的产品说:

However if you have a second stored procedure that gets the Categories for said products:

var categories = context.GetCategoriesForProducts(someproductfilter);

在EF要素称为关系修正,连接相关的实体,一旦第二实体进入的上下文中,将确保两个通话制成后,在产品中的每个产品将具有一个非空分类

a feature in EF called relationship fixup, which links related entities once the second entity enters the context, will insure that after both calls are made, each product in products will have a non-null Category.

这是不理想的,因为你正在做多个查询,但它会奏效。

This is not ideal, because you are doing more than one query, but it will work.

另一种方法是使用<一个href="http://blogs.msdn.com/meek/archive/2008/03/26/ado-entity-framework-stored-procedure-customization.aspx">EFExtensions.谁写的创建编写加载更多的数据一气呵成存储过程的能力的人。

An alternative is to use EFExtensions. The guy who wrote that created the ability to write sprocs that load more data in one go.

希望这有助于

干杯 亚历克斯

这篇关于在实体框架使用存储过程,我怎么得到有填充其导航性能的实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆