加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – subQuery中的LINQ-to-SQL和Extension方法

发布时间:2020-12-16 01:30:23 所属栏目:百科 来源:网络整理
导读:我的扩展方法是: public static IEnumerableT FilterCultureSubQueryT(this TableT t) where T : class { return t; } 我试图在这个查询中使用它 var test = from p in t.Products select new { Allo = p,Allo2 = (from pl in t.ProductLocales.FilterCultu
我的扩展方法是:

public static IEnumerable<T> FilterCultureSubQuery<T>(this Table<T> t)
    where T : class
    {
      return t;
    }

我试图在这个查询中使用它

var test = from p in t.Products
             select new
             {
               Allo = p,Allo2 = (from pl in t.ProductLocales.FilterCultureSubQuery()
                        select pl)
             };

什么应该是我的方法扩展的签名?我总是得到这个错误:

Method 'System.Collections.Generic.IEnumerable`1[ProductLocale] FilterCultureSubQuery[ProductLocale](System.Data.Linq.Table`1[ProductLocale])' has no supported translation to SQL.

我也试过这个签名:

public static IQueryable<T> FilterCultureSubQuery<T>(this Table<T> t)
    where T : class
    {
      return t;
    }

我收到了这个错误:

Method 'System.Linq.IQueryable`1[ProductLocale] FilterCultureSubQuery[ProductLocale](System.Data.Linq.Table`1[ProductLocale])' has no supported translation to SQL.

谢谢

解决方法

你方法的签名很好.问题是,如上所述,它“没有支持的SQL转换”.

DLINQ正在尝试将该语句转换为将发送到数据库的SQL行.该方法没有翻译.

我建议使用Where子句重写过滤器.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读