首页 > 代码库 > Entity Framework OData filter inherit

Entity Framework OData filter inherit

过滤继承对象 

TPH 的情况

EF : 

   return Task.FromResult<IQueryable<Parent>>(
                query.OfType<ChildA>().Where(c => c.childA == "a").Cast<Parent>().Concat(query.OfType<ChildB>().Where(c => c.childB == "b"))
            );

使用 concat 来处理 

 

OData : 

$http({
    url: "/api/parents",
    params : {
        $filter: "Project.Entity.ChildA/childA eq ‘dada‘ or Project.Entity.ChildB/Id gt 0"
    },
    method : "GET"
});

 

Entity Framework OData filter inherit