Stored procedures EF4:使用SP加载导航属性

Stored procedures EF4:使用SP加载导航属性,stored-procedures,entity-framework-4,relationship,Stored Procedures,Entity Framework 4,Relationship,我只能使用SPs从数据库加载实体。我可以使用导入功能成功加载客户: Customer cust = context.GetCustomerById(customerId); 然后我需要使用另一个SP加载客户订单集合: IEnumerable<Order> cust_orders = context.GetOrdersByCustomerId(customerId); 有没有办法在不触发Select的情况下加载Orders属性?您必须禁用LazyLoading,并通过适当的SP调用

我只能使用SPs从数据库加载实体。我可以使用导入功能成功加载客户:

Customer cust = context.GetCustomerById(customerId);
然后我需要使用另一个SP加载客户订单集合:

IEnumerable<Order> cust_orders = context.GetOrdersByCustomerId(customerId);

有没有办法在不触发Select的情况下加载Orders属性?

您必须禁用LazyLoading,并通过适当的SP调用加载订单,如下所示:

DBContext.DataBase.SqlQuery<Order>("exec spGetOrders {0}", invoiceID).ToList();
DBContext.DataBase.SqlQuery(“exec-spGetOrders{0}”,invoiceID.ToList();

您使用的是哪种实体<代码>实体对象还是POCO?ObjectContext API或DBCOTEXT API?EntityObject和ObjectContext数据库优先方法。如何“通过适当的SP调用加载订单”,以便能够像示例中那样执行foreach。我现在可以使用导入功能加载订单,但它们不会显示在“客户订单”集合中。有人吗?我们公司不可能是唯一一家限制通过SPs访问数据的公司,如果EF可以在一个方向上修复关系,为什么不可以在另一个方向上进行修复,这意味着用读取的子实体填充集合。这一定是可能的,因为MS的DataExtensions框架提供了方法绑定,这似乎正是我想要的。
DBContext.DataBase.SqlQuery<Order>("exec spGetOrders {0}", invoiceID).ToList();