LINQ到实体:工会鲜明+

编程入门 行业动态 更新时间:2024-10-21 05:52:04
本文介绍了LINQ到实体:工会鲜明+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不知道我该怎么做几个工会具有鲜明。

当我使用.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:

  • Use the overload of Distinct which does not take any compare, or
  • 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到实体:工会鲜明+

    本文发布于:2023-06-03 10:06:12,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/473777.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:实体   鲜明   工会   LINQ

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!