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?
精彩评论