【发布时间】:2014-03-18 21:22:26
【问题描述】:
我正在尝试BreezeJS。有一个要求,我可以在客户端代码中使用.expand,但是基于用户的role,服务器端不会返回.expand请求类型的所有记录。我试图创建一个自定义的BreezeQueryable 属性并覆盖一个方法来完全过滤掉额外的数据,只是为了尝试。但它抛出了一个异常。
我没有看到任何可以在服务器端执行此操作的入口点。
请指导我正确的方向,或者如果不可能,请告诉我。我只能访问通用IQueryable,如何对此执行查询?
这里有一些示例代码:
服务器:
[BreezeController]
[EnableCors("*", "*", "*")]
public class MyDataController : ApiController
{
readonly EFContextProvider<MyDbContext> _contextProvider;
public MyDataController()
{
_contextProvider = new EFContextProvider<MyDbContext>();
_contextProvider.Context.Configuration.ProxyCreationEnabled = false;
_contextProvider.Context.Configuration.LazyLoadingEnabled = false;
}
// GET api/<controller>
//Trying to use a custom attribute to filter data here
[CustomBreezeQueryable(AllowedQueryOptions = AllowedQueryOptions.All)]
[HttpGet]
public IQueryable<MyData> GetAllData()
{
var data = _contextProvider.Context.MyData;
return data;
}
}
public class CustomBreezeQueryableAttribute : BreezeQueryableAttribute
{
public override IQueryable ApplyQuery(IQueryable queryable,
ODataQueryOptions queryOptions)
{
var data = base.ApplyQuery(queryable, queryOptions);
//trying to filter out MyDataHistory for MyData for testing,
//it throws exception
//data = data.OfType<MyDataHistory>();
return data;
}
}
客户端:
breeze.EntityQuery.from("GetAllData").expand('MyDataHistory')
.using(this.manager)
.execute()
.then((data) => {
console.log(data.results[0]);
def.resolve(data.results);
});
这是我在使用OfType 时得到的exception,我想过滤,反正不使用它。
{"DbOfTypeExpression requires an expression argument with a polymorphic result type that is compatible with the type argument."}
【问题讨论】:
-
你得到什么异常?
标签: c# asp.net-web-api2 breeze