我需要找到映射到 EntityTypeConfiguration 类的表。
例如:
public class PersonMap : EntityTypeConfiguration<Person>
{
public PersonMap()
{
...
this.ToTable("Persons");
....
}
}
我需要类似反向映射的东西:
var map=new PersonMap();
string table =map.GetMappedTableName();
我怎样才能做到这一点?
最佳答案
将字段添加到 PersonMap:
public class PersonMap : EntityTypeConfiguration<Person>
{
public string TableName { get { return "Persons"; } }
public PersonMap()
{
...
this.ToTable(TableName);
...
}
}
像这样访问它:
var map = new PersonMap();
string table = map.TableName;
如果您可能不知道 map 的类型,请使用接口(interface):
public interface IMap
{
string TableName { get; }
}
public class PersonMap : EntityTypeConfiguration<Person>, IMap
{
public string TableName { get { return "Persons"; } }
public PersonMap()
{
...
this.ToTable(TableName);
...
}
}
像这样访问:
IMap map = new PersonMap();
string table = map.TableName;
关于entity-framework - 如何找到流利的API映射了哪个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12564408/