Skip to content

OrderBy with mapped EF entity property not working because of RestrictOrderByToPropertyOrField #928

@bzaugt

Description

@bzaugt

Using this with Entity Framework 8 (and sql server), OrderBy does not work when an entity property is a mapped column.

Example entity:

[Table("Invoices")]
public partial class Invoice
{
    public int Id { get; set; }

    [Column("DatePaid")] // property is mapped to the column "DatePaid" in the database
    public DateTime? PaymentDate { get; set; }
}

Then running OrderBy:

var invoices = context.Invoices;
var config = new ParsingConfig()
{
    // this is the default value, but setting it explicitly here for clarity
    RestrictOrderByToPropertyOrField = true
};
var orderedQuery = invoices.OrderBy(config, "x => x.PaymentDate == null ? 1 : 2");

Expected result: Using the default configuration, I would expect the property to be parsed and mapped correctly.

Actual result: This results in a ParseException with message: No property or field 'null' exists in type 'Invoice'

When setting RestrictOrderByToPropertyOrField to false, it works.

Also See #927

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions