I'm trying to get the SQL table name for the entity. When I work with the MetadataWorkspace queries I get lots of information from the object or the storage space. But schema name and table name are not present.
I try query all the EntityType objects for CSpace and SSpace and I can see both listed correctly but I can't figure out how to get SSpace from CSpace.
So say I have a type in the object model called User - how do I find the tablename with schema name (tkp.User) in the database?
Is there any way to do this?
There is no perfect
answer to this, but this should work...
var ssSpaceSet = objectContext.MetadataWorkspace
.GetItems<EntityContainer>(DataSpace.SSpace).First()
.BaseEntitySets
.First(meta => meta.ElementType.Name == "YourEntityName");
If you look up in debugger, Table
property should have the real table name.
You'd need to use
reflection
in the last part.
Good news is it should transparently work with EF6 too (as it has a similar base class)
(it's similar for schema
, should be in there also - this is the space
for Db/SQL mapped names, facets etc.)
See this post of mine with many details
Get Model schema to programmatically create database using a provider that doesn't support CreateDatabase
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With