Return input type of generic with type constraint in LINQ to Entities (EF4.1)

前端 未结 4 1391
春和景丽
春和景丽 2021-02-20 18:03

I have a simple extension method for filtering a LINQ IQueryable by tags. I\'m using this with LINQ to Entities with an interface of:

public interface ITaggable
         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-02-20 18:08

    I was looking for the same answer and not being satisfied with the syntactic cleanliness of the answers provided, I kept looking and found this post.

    tl;dr; - add class to your constraints and it works.

    LINQ to Entities only supports casting EDM primitive or enumeration types with IEntity interface

    public static IQueryable WhereTagged(this IQueryable set, string tag)
        where T: class, ITaggable
    

提交回复
热议问题