开发者

Query Entity Framework 4

Is it possible to run a query on an EF4.0 data context and get all objects of a certain type?

Say the context has books, genres & authors but I only have a generic parameter, t. Is it possible to get all of type just by using this t?

I don't thi开发者_如何学Cnk it is :(


 var x = from z in context.CreateObjectSet<Person>()
                    select z;


I believe this will do the trick.

ObjectSet<T> set = (ObjectSet<T>)context.GetType().GetProperties().FirstOrDefault(p => p.PropertyType.IsGenericType &&
                p.PropertyType.GetGenericTypeDefinition() == typeof(ObjectSet<T>)).GetValue(this, null);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜