C# 实体框架获取模型类名字符串的表名和属性
我试图从目录(DatabaseModels)中获取文件,并获取模型类名字符串的表名和属性 结构C# 实体框架获取模型类名字符串的表名和属性,c#,C#,我试图从目录(DatabaseModels)中获取文件,并获取模型类名字符串的表名和属性 结构 数据库模型 CalendarItems.cs ConfigurationObject.cs ContentBlock.cs EmailTemplate.cs NewsItem.cs Page.cs var fname=string.Empty; WmoPlatformContext=WmoPlatformContext.Create(); foreach(directoryInfo.GetFi
- 数据库模型
- CalendarItems.cs
- ConfigurationObject.cs
- ContentBlock.cs
- EmailTemplate.cs
- NewsItem.cs
- Page.cs
var fname=string.Empty;
WmoPlatformContext=WmoPlatformContext.Create();
foreach(directoryInfo.GetFiles()中的FileInfo文件)
{
fname=Path.GetFileNameWithoutExtension(file.Name);
控制台写入线(fname);
Type Type=Type.GetType(fname,true);
var o=Activator.CreateInstance(类型);
var tableName=context.GetTableName();
PropertyInfo[]PropInfo=typeof(o).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
}
o
在GetTableName()
和typeof()
中不起作用(错误:o
是一个变量,但与类型一样使用),有什么方法可以实现这一点吗 更改为GetTableName()@Nikita相同错误:type是一个变量,但与type一样使用
更改为GetTableName()@Nikita仍然会给我相同的错误,我想你的意思是typeof
而不是typeof
?是的,你检查过了吗?更改为GetTableName()@Nikita相同的错误:type是一个变量,但它的用法类似于类型
更改为GetTableName()@Nikita给了我同样的错误,我想你的意思是typeof
而不是typeof
?是的,你检查过了吗?
var fname = string.Empty;
WmoPlatformContext context = WmoPlatformContext.Create();
foreach (FileInfo file in directoryInfo.GetFiles())
{
fname = Path.GetFileNameWithoutExtension(file.Name);
Console.WriteLine(fname);
Type type = Type.GetType(fname, true);
var o = Activator.CreateInstance(type);
var tableName = context.GetTableName<o>();
PropertyInfo[] propInfos= typeof(o).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
}