开发者

Entity Framework - Common Query

referencing at previous post (Entity Wrapper - Custom) I still have some difficult about generic query to retrieving common field.

I've a simple interface with one field only. All my entities inheritance from my interface. Then I've a class encapsulating my o开发者_开发知识库bjectContext typed. Well, now I need to execute a linq query to get my IQuerable object. The following snippet goes on error at building time:

public IQueryable<T> GetQuery<T>() where T : IEntity 
{
    var query =
        GetObjectSetSomehow; //problem: I don't know the objectSet type here!!   
    return query.Where(p => p.field == "..."); 
}

But especially my issue is about impossibility to make casting from IQuerable where T : MyInterface to ObjectSet

Any suggestion wiil be appreciated..


Maybe ObjectContext.CreateObjectSet Method could help you. As MSDN says, Method

Creates a new ObjectSet instance that is used to query, add, modify, and delete objects of the specified entity type.

public static IQueryable<T> Create<T>(ObjectContext context) where T : class, IEntity
    {
        var query = context.CreateObjectSet<T>().AsQueryable();
        return query.Where(x => true);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜