LINQ oddity?

Posts   
 
    
Posts: 134
Joined: 10-Jan-2007
# Posted on: 01-Apr-2010 21:23:13   

Changed some code around today (property to a method) and am now getting the error: The binary operator Equal is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'. on a LINQ query.

The code (contrived):



public class Something
{
    private LoginEntity _login;
    public LoginEntity Login
    {
       get { 
         if (_login == null) 
           _login = new LoginEntity(1); 
         return _login;
        }
     }
    public LoginEntity GetLogin()
    {
         return Login;
     }

     private IList<OrdersEntity> GetOrders()
     {
        //See below
     }
}

Notes: the LoginEntity ClientId is nullable, the OrdersEntity ClientId is not (though if it is, the error still happens).

This Errors out (using method):

return new LinqMetadata().Orders.Where(o => o.ClientId == GetLogin().ClientId).ToList();

So does this (using field):

return new LinqMetadata().Orders.Where(o => o.ClientId == _login.ClientId).ToList();

This does not error (using property):

return new LinqMetadata().Orders.Where(o => o.ClientId == Login.ClientId).ToList();

If I make the property anything but public, it errors also. This also does not error (using local variable):

int? clientId = _login.ClientId;
return new LinqMetadata().Orders.Where(o => o.ClientId == clientId).ToList();

Should these all work the same?

Brian

ORM Lib Version: 2.6.9.327 LINQ Lib Version: 2.6.9.331 SQL Server Lib Version: 2.6.8.1114

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 01-Apr-2010 22:09:40   

could you try with the latest runtimes? yours are over a year old simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 01-Apr-2010 22:25:27   

Um, the latest build fixed it. flushed

Thanks!