A problem with LINQ All()

Mar 16, 2015 at 10:45 AM
I have run into a problem with the usage of All() in LINQ queries. Here's a representing test:
    public void TestLinqAll() {
      var app = SetupHelper.BooksApp;
      var session = app.OpenSession();
      var books = session.EntitySet<IBook>().Where(b => b.Authors.All(a => a.Bio != null)).ToArray();
      Assert.AreEqual(3, books.Length);
This throws the following exception:
The binary operator Equal is not defined for the types 'System.Int64' and 'System.Int32'
at line 1414 in ExpressionDispatcher.Analyzer.cs

I have fixed it by changing that line to:
var allExpression = Expression.Equal(allBuilderContext.CurrentSelect, Expression.Constant(Convert.ChangeType(0, allBuilderContext.CurrentSelect.Type)));
Mar 16, 2015 at 5:31 PM
thanks, will look at it.
Looks like this case is a part of common problem - the SQL functions like Count return different types for different server types: Int32 or Int64 or even UInt64. So one has to adjust code for this, I remember struggled quite a bit with Count.
Mar 16, 2015 at 7:20 PM
yep, that's the case, translation uses Count(*) which returns Int64 for SQLite; and your fix is correct.