如何动态创建所有db上下文表的对象。以下是我迄今为止尝试过的代码并且卡住了。
PB_Pan_DvContext obj = new PB_Pan_DvContext();
var metadata = ((IObjectContextAdapter)obj).ObjectContext.MetadataWorkspace;
var tables = metadata.GetItemCollection(DataSpace.SSpace)
.GetItems<EntityContainer>()
.Single()
.BaseEntitySets
.OfType<EntitySet>()
.Where(s => !s.MetadataProperties.Contains("Type")
|| s.MetadataProperties["Type"].ToString() == "Tables");
foreach (var table in tables)
{
var tableName = table.MetadataProperties.Contains("Table")
&& table.MetadataProperties["Table"].Value != null
? table.MetadataProperties["Table"].Value.ToString()
: table.Name;
var tableSchema = table.MetadataProperties["Schema"].Value.ToString();
// here i want to create dynamic object of table
}
有关如何实现此问题的任何线索?任何帮助将不胜感激。