Answer the question
In order to leave comments, you need to log in
Get schema name for each entity object?
I have the following code
using (WdmEntities context = new WdmEntities())
{
//get object models from context
ObjectContext objContext = ((IObjectContextAdapter)context).ObjectContext;
var container = objContext.MetadataWorkspace.GetEntityContainer(objContext.DefaultContainerName, DataSpace.CSpace);
List<string> schemas = new List<string>();
foreach (var set in container.BaseEntitySets)
{
foreach (var metaproperty in set.MetadataProperties)
{
//here
if(metaproperty.Name == "Schema")
{
//but metaproperty.Value == NULL
schemas.Add(metaproperty.Value);
}
}
}
}
Answer the question
In order to leave comments, you need to log in
This is how I managed to get the schema name
using (WdmEntities context = new WdmEntities())
{
//get object models from context
ObjectContext objContext = ((IObjectContextAdapter)context).ObjectContext;
//get all full names types from object model
var fullNameTypes = objContext.MetadataWorkspace.GetItems<EntityType>(DataSpace.OSpace);
///////////////////
var conStr = objContext.Connection.ConnectionString;
var connection = new EntityConnection(conStr);
var workspace = connection.GetMetadataWorkspace();
var entitySets = workspace.GetItems<EntityContainer>(DataSpace.SSpace).First().BaseEntitySets;
for (int i = 0; i < fullNameTypes.Count; i++)
{
Type type = Type.GetType(fullNameTypes[i].FullName);
string schema = entitySets[type.Name].MetadataProperties["Schema"].Value.ToString();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question