Search code examples
c#entity-framework-6odata

Apply oData filter on IQueryable throws ODataException Could not find property


I'm using Entity Framework with OData, Having two classes like this:

public class Foo {
    public virtual B b {get; set;}
}
public class B {
    public int c {get; set;}
}

Executing query like this from the dbSet:

 var query = Foos.Where(x => x.id == 1)

And having the following oData : (B/c eq 3)

Apply filter on the IQueryable result (query):

FilterQueryOption filter = new FilterQueryOption(queryFilter, ODataQueryContext);
var q = filter.ApplyTo(query, new ODataQuerySettings());

Throws oDataException with message: Could not find a property named b on type Foo


Solution

  • public class Foo
    { 
        [ForeignKey("B")]
        public int c { get; set; }
        public virtual B B { get; set; }
    }