DynamicLinq c#在join中不工作

本文关键字:工作 join DynamicLinq | 更新日期: 2023-09-27 18:10:48

我在c#项目中使用DynamicLinq.

当我使用"order by","skip"等做一个简单的选择时,效果很好。

但是如果你加入了restona一个简单的错误:

Error   3   Instance argument: cannot convert from 'int?' to 'System.Linq.IQueryable'   J:'C#'ERP'ERP'Helpers'ListagemPadrao.cs 23  25  ERP
Error   2   'int?' does not contain a definition for 'OrderBy' and the best extension method overload 'System.Linq.Dynamic.DynamicQueryable.OrderBy(System.Linq.IQueryable, string, params object[])' has some invalid arguments    J:'C#'ERP'ERP'Helpers'ListagemPadrao.cs 23  25  ERP
SQL工作:

var lista =
  from a in db.Usuario.AsQueryable()
      .OrderBy(aOrderna + " " + aOrdenaTipo)
      .Skip(aIniciarNoRegistro)
      .Take(aQtdeRegistro)                    
      select new
      {
          a.UsuarioID,
          a.Nome,
          a.Login,
          a.Email
      };   

SQL not work:

var lista =
  from a in db.Usuario.AsQueryable()
  join b in db.UsuarioAcesso.AsQueryable() on a.UsuarioID equals b.UsuarioID 
      .OrderBy(aOrderna + " " + aOrdenaTipo)
      .Skip(aIniciarNoRegistro)
      .Take(aQtdeRegistro)                    
      select new
      {
          a.UsuarioID,
          a.Nome,
          a.Login,
          a.Email
      };

DynamicLinq c#在join中不工作

你试过将其转换为整型吗?表示它是可空的,因此它可能不会包含任何扩展方法。

这个问题的解决方案是:

var lista =
  (from a in db.Usuario.AsQueryable()
  join b in db.UsuarioAcesso.AsQueryable() on a.UsuarioID equals b.UsuarioID   
  select new
  {
      a.UsuarioID,
      a.Nome,
      a.Login,
      a.Email
  })
  .OrderBy(aOrderna + " " + aOrdenaTipo)
  .Skip(aIniciarNoRegistro)
  .Take(aQtdeRegistro);

但不明白为什么它工作得很好....TKS from help