从EF选择返回元组
如何使用EF4在Select中检索元组?
var productCount = (from product in context.products select new Tuple(product, products.Orders.Count));
要么
var productCount = (from product in context.products select Tuple.Create(product, products.Orders.Count));
entity framework说第一种情况不能使用空构造函数,而第二种情况则不能识别Tuple.Create方法。
如何切换到投影的LINQ到对象:
var productCount = from product in context.products select new {Product = product, Count = products.Orders.Count }; var final = from item in productCount.AsEnumerable() select Tuple.Create(item.Product, item.Count);
尝试
var productCount = from product in context.products select new { product, Count = products.Orders.Count };
这将返回一个非常接近元组的匿名类型http://msdn.microsoft.com/en-us/library/bb738512.aspx
- 在Using语句中从DataLayer返回DataReader
- 实现IEnumerable 和IEnumerable.GetEnumerator()不能公开,为什么?
- Int32.TryParse()在失败时返回零 – 成功还是失败?
- Linq to XML:xml标记中的冒号问题
- 即使所有项目都引用4.3.1,.NET运行时也会尝试加载FSharp.Core 4.3.0
- 在C#中更新foreach循环中的struct
- 如何在选中时更改System.Windows.Forms.ToolStripButton高亮/背景颜色?
- 在将.NET Core控制台应用程序部署到Azure WebJobs时加载hostpolicy.dll时出错
- 在C#应用程序中查找内存泄漏