Use of “Single” in Dynamic Linq

后端 未结 2 1789
栀梦
栀梦 2021-01-14 09:50

I am trying to convert a Linq query that I have working in Linq to be able to work in dynamic linq (using System.Linq.Dynamic) because I want a user to be able to form their

2条回答
  •  北海茫月
    2021-01-14 10:37

    Get the source of Linq.Dynamic, copy paste the Where method, change the signature and the string with the function name inside the method and you're good to go. I did it to add Single First etc, I can't copy it here because I'm not on my dev machine but I'll do it later if necessary ;)

    EDIT: here's the Single method if you decide to use it:

    public static object Single(this IQueryable source)
        {
            if (source == null) throw new ArgumentNullException("source");
            return source.Provider.Execute(
                Expression.Call(
                    typeof(Queryable), "Single",
                    new Type[] { source.ElementType },
                    source.Expression));
        }
    

提交回复
热议问题