-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query: The binary operator AndAlso is not defined for the types 'System.Nullable`1[System.Boolean]' and 'System.Boolean' #10721
Comments
Can you try the workaround described here? (i.e. disable null OData null propagation) Those problems generally stem from the fact that OData modifies the expression tree to handle the cases where expected value is non-nullable but null can occur. EF Core does similar thing under the hood, so it shouldn't be needed from the OData side, making the tree bit less complicated. It is a bug in EF nonetheless - the expression trees that OData generates are correct, we are just not used to seeing them elsewhere. |
@maumar thank you for the workaround, it did in fact work 😄 |
Tried following repro which does similar query to it and working in 3.1 In the absence of original model and OData, we cannot verify if the actually reported scenario is fixed. public class Program
{
public static void Main(string[] args)
{
using (var db = new MyContext())
{
// Recreate database
db.Database.EnsureDeleted();
db.Database.EnsureCreated();
// Seed database
db.SaveChanges();
}
using (var db = new MyContext())
{
// Run queries
var query = db.Employees.Where(e => e.IsActive == true && e.DepartmentId == 23).Take(25).ToList();
}
Console.WriteLine("Program finished.");
}
}
public class MyContext : DbContext
{
private static ILoggerFactory ContextLoggerFactory
=> LoggerFactory.Create(b =>
{
b
.AddConsole()
.AddFilter("", LogLevel.Debug);
});
// Declare DBSets
public DbSet<Employee> Employees { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Select 1 provider
optionsBuilder
//.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=_ModelApp;Trusted_Connection=True;Connect Timeout=5;ConnectRetryCount=0")
//.UseSqlite("filename=_modelApp.db")
.UseInMemoryDatabase(databaseName: "_modelApp")
//.UseCosmos("https://localhost:8081", @"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", "_ModelApp")
.EnableSensitiveDataLogging()
.UseLoggerFactory(ContextLoggerFactory);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Configure model
}
}
public class Employee
{
public int Id { get; set; }
public bool? IsActive { get; set; }
public int DepartmentId { get; set; }
} I am making this issue as closed-fixed. If you still hit issues when using 3.1 packages, please file a new issue so we can further investigate. |
While attempting to run an OData query with a
$filter
that contains 2 conditionals, one of which is on a boolean property, I am receiving the following exception.I saw the following related (and closed/merged) issues and PRs (and is the reason I tried the latest nightly, although it did not resolve the issue)
Steps to reproduce
Attempt to use an OData query with at least 1 boolean property:
/Employees?$filter=IsActive eq true and DepartmentId eq 23&$top=25
I would have left an issue on OData/WebApi but it appears to be specifically an EntityFrameworkCore issue
Further technical details
EF Core version:
2.1.0-preview1-28103
Database Provider:
Microsoft.EntityFrameworkCore.SqlServer
Operating system: Mac
IDE: Visual Studio for Mac / dotnet cli (2.0.3)
The text was updated successfully, but these errors were encountered: