开发者

Entity Framework 4.1: List of all of my class names

开发者 https://www.devze.com 2023-03-24 12:55 出处:网络
Is there a way to get a list of all of 开发者_Python百科my entity class names from EF?I can use ObjectContext.GetKnownProxyTypes()

Is there a way to get a list of all of 开发者_Python百科my entity class names from EF? I can use

ObjectContext.GetKnownProxyTypes()

-But this method only returns types that have been used in this current context. I need all of the types that are in my DBContext.

DBContext.

Thanks


You can try this:

ObjectContext context = ((IObjectContextAdapter)dbContext).ObjectContext;
EntityContainer container = context.MetadataWorkspace
   .GetEntityContainer(context.DefaultContainerName, DataSpace.CSpace);
string[] typeNames = container.BaseEntitySets
                              .OfType<EntitySet>()
                              .Select(es => es.ElementType.Name);

I'm not sure if adapter will correctly configure DefaultContainerName. It shoud probably be the same as your derived context class name.


Could you not use Reflection to get the list of Entity types from the DbContext?

0

精彩评论

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