我在我的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不起作用:
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
};
答案 0 :(得分:0)
您是否尝试将其转换为int - int?表示它可以为空,因此它可能没有任何扩展方法。
答案 1 :(得分:0)
问题的解决方案是:
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);
但不明白为什么它运作良好.... 来自帮助