c# - Get Entity Table Name - EF7 -


as question states, know how entity table name in entity framework 7?

i have code in entity framework 6.1 (from site, cant find link), none of interfaces/objects seem referenced in entity framework 7.

code ef6.1

public string gettablename(type type) {     var metadata = ((iobjectcontextadapter)this).objectcontext.metadataworkspace;     var objectitemcollection = ((objectitemcollection)metadata.getitemcollection(dataspace.ospace));     var entitytype = metadata.getitems<entitytype>(dataspace.ospace).single(e => objectitemcollection.getclrtype(e) == type);     var entityset = metadata.getitems(dataspace.cspace).where(x => x.builtintypekind == builtintypekind.entitytype).cast<entitytype>().single(x => x.name == entitytype.name);     var entitysetmappings = metadata.getitems<entitycontainermapping>(dataspace.csspace).single().entitysetmappings.tolist();      entityset table = null;      var mapping = entitysetmappings.singleordefault(x => x.entityset.name == entityset.name);     if (mapping != null)     {         table = mapping.entitytypemappings.single().fragments.single().storeentityset;     }     else     {         mapping = entitysetmappings.singleordefault(x => x.entitytypemappings.where(y => y.entitytype != null).any(y => y.entitytype.name == entityset.name));          if (mapping != null)         {             table = mapping.entitytypemappings.where(x => x.entitytype != null).single(x => x.entitytype.name == entitytype.name).fragments.single().storeentityset;         }         else         {             var entitysetmapping = entitysetmappings.single(x => x.entitytypemappings.any(y => y.isofentitytypes.any(z => z.name == entityset.name)));             table = entitysetmapping.entitytypemappings.first(x => x.isofentitytypes.any(y => y.name == entityset.name)).fragments.single().storeentityset;         }     }      return (string)table.metadataproperties["table"].value ?? table.name; } 

the thing need achieve same this:

public string gettablename(type type) {    return this.model.getentitytype(type).sqlserver().tablename; } 

ps: i'm assuming method declared in dbcontext class, otherwise change this keyword dbcontext instance.

update

getentitytype renamed findentitytype. can find more info in link

return this.model.findentitytype(type).sqlserver().tablename; 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -