How to find which table is mapped using the free API?

I need to find which table maps to the EntityTypeConfiguration class. For instance:

public class PersonMap : EntityTypeConfiguration<Person> { public PersonMap() { ... this.ToTable("Persons"); .... } } 

I need something like a reverse mapping:

 var map=new PersonMap(); string table =map.GetMappedTableName(); 

How can i achieve this?

+4
source share
1 answer

Add a field to PersonMap:

 public class PersonMap : EntityTypeConfiguration<Person> { public string TableName { get { return "Persons"; } } public PersonMap() { ... this.ToTable(TableName); ... } } 

Access to it:

 var map = new PersonMap(); string table = map.TableName; 

If you do not know the type of card, use the interface:

 public interface IMap { string TableName { get; } } public class PersonMap : EntityTypeConfiguration<Person>, IMap { public string TableName { get { return "Persons"; } } public PersonMap() { ... this.ToTable(TableName); ... } } 

Access to this:

 IMap map = new PersonMap(); string table = map.TableName; 
+2
source

Source: https://habr.com/ru/post/1435902/


All Articles