0

I am using in my C # projects DynamicLinq.

When I do a simple select using "order by", "skip", etc. works perfectly.

But if you do join restona simple error:

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 work:

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
      };
Tiedt Tech
  • 719
  • 15
  • 46

2 Answers2

0

Have you tried casting it to an int - The int? indicates it is nullable, so it probably wont have any of the extension methods in it.

Andrew
  • 2,315
  • 3
  • 27
  • 42
  • 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 – Tiedt Tech Apr 25 '13 at 14:51
  • I've never used DLINQ before, but generally in order for your join to work you'd have to have non-null, matching values in your two tables (I am presuming db is a database connection). I've never used AsQueryable before - is this a DLINQ specific thing? The join command is just the equivalent of a SQL inner join - if you need to do left joins or whatever then it is far more complicated – Andrew Apr 25 '13 at 14:59
0

The solution to the problem was:

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);

But do not understand why it works well .... tks from help

Tiedt Tech
  • 719
  • 15
  • 46