-
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
Unable to cast object of type 'PropertyExpression' to type 'NullConditionalExpression' for some queries with include, and multiple orderbys #8369
Comments
The Context
DrDr
DrHistory
DrStatus
DrEmployee
DrProj
DrAta
|
Simplified repro: class Program
{
static void Main(string[] args)
{
using (var ctx = new DrdbContext())
{
ctx.Database.EnsureDeleted();
ctx.Database.EnsureCreated();
}
using (var ctx = new DrdbContext())
{
var query = ctx.DrDr
.Include(w => w.DrHistory)
.OrderBy(w => w.ProjectNavigation.Nn)
.ThenBy(w => w.ProjDr);
var result = query.ToList();
}
}
}
public class DrdbContext : DbContext
{
public virtual DbSet<DrDr> DrDr { get; set; }
public virtual DbSet<DrHistory> DrHistory { get; set; }
public virtual DbSet<DrProj> DrProj { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=.;Database=Repro8369;Trusted_Connection=True;MultipleActiveResultSets=True");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<DrDr>(entity =>
{
entity.HasOne(d => d.ProjectNavigation)
.WithMany(p => p.DrDr)
.HasForeignKey(d => d.Project)
.OnDelete(DeleteBehavior.Restrict);
});
}
}
public class DrDr
{
public int Id { get; set; }
public int ProjDr { get; set; }
public int Project { get; set; }
public ICollection<DrHistory> DrHistory { get; set; }
public DrProj ProjectNavigation { get; set; }
}
public class DrHistory
{
public int Id { get; set; }
}
public class DrProj
{
public int Id { get; set; }
public string Nn { get; set; }
public ICollection<DrDr> DrDr { get; set; }
} |
Please what is the state of this issue now? I am having similar error in my project. |
I noticed that when I add OrderBy and OrderByDescending clause to my query, I get the error
But when I remove them, the code is executed. I didn't have this error in netcoreapp1.1 until I upgraded to netcoreapp2.0. This is my code
GetAllBooks () is a function that simply returns this
##Resolved## Adding to ToList() before OrderBy solved the error
|
@smithaitufe that's not a solution, the point is to perform the ordering on the server side, before pagination. |
Problem is in the include pipeline, so current workaround would be to write the includes by hand using joins. This is very painful however. The underlying problem doesn't seem complicated so I'm pretty sure it will get fixed before 2.0 is shipped. |
….PropertyExpression' to type 'Microsoft.EntityFrameworkCore.Query.Expressions.Internal.NullConditionalExpression' Problem was that we had incorrect assumption in the include compiler when performing orderby lifting. When looking for duplicate orderings we always assumed that subquery projections would be an expression of a particular shape (methood call wrapped around NullConditionalExpression). However, this is not accurate because any expression could be there if it was a previous orderby expression. Fix is to look for duplicate expression more defensively, using soft rather than explicit cast and also taking MemberExpression into account.
…type 'NullConditionalExpression' for some queries with include, and multiple orderbys Problem was that we had incorrect assumption in the include compiler when performing orderby lifting. When looking for duplicate orderings we always assumed that subquery projections would be an expression of a particular shape (methood call wrapped around NullConditionalExpression). However, this is not accurate because any expression could be there if it was a previous orderby expression. Fix is to look for duplicate expression more defensively, using soft rather than explicit cast and also taking MemberExpression into account.
…type 'NullConditionalExpression' for some queries with include, and multiple orderbys Problem was that we had incorrect assumption in the include compiler when performing orderby lifting. When looking for duplicate orderings we always assumed that subquery projections would be an expression of a particular shape (methood call wrapped around NullConditionalExpression). However, this is not accurate because any expression could be there if it was a previous orderby expression. Fix is to look for duplicate expression more defensively, using soft rather than explicit cast and also taking MemberExpression into account.
…type 'NullConditionalExpression' for some queries with include, and multiple orderbys Problem was that we had incorrect assumption in the include compiler when performing orderby lifting. When looking for duplicate orderings we always assumed that subquery projections would be an expression of a particular shape (methood call wrapped around NullConditionalExpression). However, this is not accurate because any expression could be there if it was a previous orderby expression. Fix is to look for duplicate expression more defensively, using soft rather than explicit cast and also taking MemberExpression into account.
…type 'NullConditionalExpression' for some queries with include, and multiple orderbys Problem was that we had incorrect assumption in the include compiler when performing orderby lifting. When looking for duplicate orderings we always assumed that subquery projections would be an expression of a particular shape (methood call wrapped around NullConditionalExpression). However, this is not accurate because any expression could be there if it was a previous orderby expression. Fix is to look for duplicate expression more defensively, using soft rather than explicit cast and also taking MemberExpression into account.
…type 'NullConditionalExpression' for some queries with include, and multiple orderbys Problem was that we had incorrect assumption in the include compiler when performing orderby lifting. When looking for duplicate orderings we always assumed that subquery projections would be an expression of a particular shape (methood call wrapped around NullConditionalExpression). However, this is not accurate because any expression could be there if it was a previous orderby expression. Fix is to look for duplicate expression more defensively, using soft rather than explicit cast and also taking MemberExpression into account.
fixed in fafb2dd |
I'm getting the exception in the title when using a very specific
ThenBy
expression. I'll include my EF model in a comment below since it's very large. I don't have a stack trace since I'm using the NuGet package directly, but it should be easily reproducible.Steps to reproduce
The code that produces the exception, as stripped down as possible.
Removing
ThenBy
fixes it. Swapping the lambda expressions betweenOrderBy
andThenBy
also fixes it. Though obviously the result isn't as intended.Further technical details
EF Core version: v2.0.0-preview2-24770
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 7 SP1
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered: