KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
We have a class called Task: public partial class Task : EntityObject { public EntityCollection<TaskUser> TaskUsers { get {...} set{...} } } It has navigation property called TaskUsers, which contains users attached to this taks: public partial class TaskUser : EntityObject { public User User { get {...} set { } } } Every TaskUser object has User object. We are given IQueryable<Task> tasks . We want to find tasks assigned to user with ID = 1. When we use tasks.Where(t => t.TaskUsers.Any(a => a.User.ID == 1)) everything works fine. When we use Func<TaskUser, bool> function = a => a.User.ID == 1; return tasks.Where(t => t.TaskUsers.Any(function)); we get nice 'Internal .NET Framework Data Provider error 1025' error. Why? I want to build much more complicated filters using Expression class, but if I can't pass simple Func , this can't be done. What should I do? EDIT Maybe Func<TaskUser, bool> function = a => a.User.ID == 1; return tasks.Where(t => t.TaskUsers.Any(function)); doesn't work, but Expression<Func<TaskUser, bool>> expression = a => a.User.ID == 1; return tasks.Where(t => t.TaskUsers.AsQueryable().Any(expression)); works! That is all I needed.
Tags (comma-separated)
Save Edits
Cancel