I'm trying out BreezeJS
. There is a requirement that I can use .expand
in the client side code, but based on the role
of the user, the server side will not return all the records for the .expand
requested type. I tried to create a custom BreezeQueryable
attribute and override a method to completely filter out the extra data first just to try. But it threw an exception.
I don't see any entry point where I can do that on the server side.
Please guide me in the right direction, or let me know if that's not possible. I only have access to generic IQueryable
, how do I perform queries on this?
Here's some sample code:
Server:
[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;
}
}
Client side:
breeze.EntityQuery.from("GetAllData").expand('MyDataHistory')
.using(this.manager)
.execute()
.then((data) => {
console.log(data.results[0]);
def.resolve(data.results);
});
This is the exception
I get when using OfType
, and I would like to filter, not use that anyways.
{"DbOfTypeExpression requires an expression argument with a polymorphic result type that is compatible with the type argument."}