Reputation: 13
I'm trying to run a query on the database server side to load the entire filtered result into the application. I tried to perform filtering without using my own methods and it worked without errors. But if I use my own method in Expression Tree, I get this error during execution:
Failure: Direct client side execution of 'eventItem.GetEventOfficesIds()' failed
private static IQueryable<Guid> GetEventOfficesIds(this Event eventItem)
{
IQueryable<Guid> officesIds;
if (eventItem.GetValue<bool?>("IsPublicNews") != null &&
eventItem.GetValue<bool?>("IsPublicNews").HasValue && eventItem.GetValue<bool?>("IsPublicNews").Value)
{
officesIds = new List<Guid>().ToArray().AsQueryable();
}
else
{
officesIds = eventItem.GetValue<TrackedList<Guid>>("Offices")?.ToArray().AsQueryable();
}
return officesIds;
}
...
EventsManager manager = EventsManager.GetManager();
IQueryable<Event> eventItems = manager.GetEvents();
Expression<Func<Event, bool>> officeFilter = eventItem =>
eventItem.GetEventOfficesIds().Contains(office.Value) && !eventItem.GetEventOfficesIds().Any();
if (office != null && office.Value != Guid.Empty)
{
eventItems = eventItems.Where(officeFilter);
}
Can I change the code of my method or OpenAccess ORM does not support executing methods written manually?
Upvotes: 0
Views: 105
Reputation: 3793
I would simplify it to something like this:
using Telerik.Sitefinity.Data.Linq.Dynamic;
EventsManager manager = EventsManager.GetManager();
IQueryable<Event> eventItems = manager.GetEvents();
if (office != null && office.Value != Guid.Empty)
{
eventItems = eventItems
.Where("IsPublicNews = true")
.Where(e => e.GetValue<TrackedList<Guid>>("Offices")?.ToArray().Contains(office.Value))
}
Upvotes: 0