Passing func as parameter in Linq to Entities and 'Internal .NET Framework Data Provider error 1025' error

前端 未结 1 1554
面向向阳花
面向向阳花 2020-12-31 02:21

We have a class called Task:

public partial class Task : EntityObject
{
    public EntityCollection TaskUsers { get {...} set{...} } 
}


        
相关标签:
1条回答
  • 2020-12-31 03:03

    Well the EF can only translate Expressions, not functions.

    i.e. it can translate this:

    Expression<Func<TaskUser,bool>> 
    

    but not this:

    Func<TaskUser,bool>
    

    As for how to merge expressions (in pseudo code):

    Expression<Func<TaskUser, bool>> expression = a => a.User.ID == 1;
    return tasks.Where(t => t.TaskUsers.Any(expression));
    

    There are probably some Expression guru's who can help with that.

    I suggest a followup question focused on that particular problem

    Alex

    0 讨论(0)
提交回复
热议问题