我不知道我该怎么做几个工会具有鲜明。
当我使用.Distinct用的IEqualityComparer一个例外扔:
LINQ到实体无法识别方法System.Linq.IQueryable
我的代码是
VAR工会= query.Union(QUERY1).Union(QUERY2); 联合= union.Distinct(新EqualityComparerTransaction());解决方案
LINQ到实体不支持过载鲜明这需要一个的IEqualityComparer 。当你想想,这真的不能,因为LINQ to Entities查询将被转换为SQL,你不能转换接口参考SQL。
因此,你必须:
把两个列表到对象空间并执行鲜明在LINQ到对象,像这样的:
VAR工会= query.Union(QUERY1).Union(QUERY2); =工会union.AsEnumerable()是不同的(新EqualityComparerTransaction());
当然,这里的风险是,你可能带来太多的记录:从DB服务器回来。你还可以在为了做到服务器和在对象空间中的另一部分上的比较的部分中使用这两种技术
I don't know how I can do several union with a distinct.
When I use .Distinct with an IEqualityComparer an exception in threw :
LINQ to Entities does not recognize the method 'System.Linq.IQueryable'
My code is
var union = query.Union(query1).Union(query2); union = union.Distinct(new EqualityComparerTransaction());解决方案
LINQ to Entities does not support the overload of Distinct which takes an IEqualityComparer. When you think about it, it really can't, because LINQ to Entities queries will be converted to SQL, and you cannot convert an interface reference to SQL.
Therefore, you must either:
Bring both lists into object space and do the Distinct in LINQ to Objects, like this:
var union = query.Union(query1).Union(query2); union = union.AsEnumerable().Distinct(new EqualityComparerTransaction());Naturally, the risk here is that you might bring too many records back from the DB server. You could also use both of these techniques in order to do a portion of the comparison on the server and another portion in object space.
更多推荐
LINQ到实体:工会鲜明+
发布评论