我试图重用查询的一部分,因为它足够复杂,我想尽量避免代码重复。实体框架查询如何重用(使用方法)?
看来,调用查询内的任何方法时,你结束了:
LINQ到实体不承认 方法{X}方法,并 这种方法不能被翻译成 一个店内表达
我想最好做的是使用:
var q = from item in context.Items
where item.SomeCondition == true
select new {Item = item, Connections = GetConnections(item)};
GetConnections
是在item
上执行查询的方法。我试图在GetConnections
中重复使用(相当复杂的)查询,但我不确定如何使其工作。
当前GetConnections的签名是这样的:
IQuerable<Connection> GetConnections(MyItem item)
任何想法如果您没有'IQuerable'而只是'Customer '?这甚至可能吗? –
2010-07-13 08:28:45
CustomerWithRecentOrders x = myContext.Customers .Where(c => c == myCustomer).Select(selector).Single() – 2010-07-13 12:48:34