Customer.OrderCount属性映射 [英] Customer.OrderCount property mapping

查看:62
本文介绍了Customer.OrderCount属性映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于客户实体可以拥有多个订单,我希望客户提供一个属性,提供他们拥有的订单数量。


我可以使用MapSingleType停止将OrderCount列映射到customer表,但不知道有效填充它的最佳方法。


有什么想到的吗?

解决方案

< span style ="font-family:Calibri"> Zaphod,


 


如果我理解你正确的要求你是一种查询关系并计算订单数量的方法
没有loa将所有订单记入内存。  这是我们正在考虑在即将发布的版本中更容易实现的内容但是现在Rowan撰写了一篇很好的博客文章,描述了一种方法: 
http://romiller.com/2010/08/14/ef-ctp4-tips-tricks-querying-导航 - 无加载/  
在他的帖子中,他最终使用这一行:


 


  var prodCount = ctx.CreateNavigationQuery(food,c = > c.Products).Count();


 


计算某个类别的产品数量而不加载所有产品。 
您应该能够与客户和订单示例做类似的事情。


 


< span style ="font-family:Calibri">谢谢,


Arthur < /跨度>


Given a customer entity that can have many orders, I want a property on the customer that provides a count of the number of orders they have.

I can use MapSingleType to stop the OrderCount column from being mapped to the customer table, but do not know the best way to populate it efficiently.

Anything spring to mind?

解决方案

Zaphod,

 

If I understand you correctly what you are essentially asking for is a way to query the relationship and count the number of orders without loading all of the orders into memory.  This is something that we’re looking at making easier in an upcoming release but for now Rowan wrote a nice blog post describing one way you could do it:  http://romiller.com/2010/08/14/ef-ctp4-tips-tricks-querying-navigations-without-loading/.  In his post he ends up using this line:

 

 var prodCount = ctx.CreateNavigationQuery(food, c => c.Products).Count();

 

to count the number of products on a category without loading all the products.  You should be able to do something similar with your customers and orders example.

 

Thanks,

Arthur


这篇关于Customer.OrderCount属性映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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