2012-09-24 2 views
4

어떤 테이블이 EntityTypeConfiguration 클래스에 매핑되는지 찾아야합니다. 예를 들어 :유창한 API로 매핑되는 테이블을 찾는 방법은 무엇입니까?

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

어떻게 이것을 달성 할 수

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

     } 
    } 

나는 역 매핑 같은 뭔가가 필요?

답변

2

PersonMap에 필드를 추가

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

액세스를과 같이 :

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

: 당신이지도의 유형을 알 수 없습니다 경우

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

는 인터페이스를 사용 다음과 같은 액세스 :

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

EntityTypeConfiguration을 사용하지 않고 TableName을 찾는 것이 좋습니다. 하지만 열 이름은 무엇입니까? PersonMap의 예 : this.ToTable (TableName); this.Property (t => t.Code) .HasColumnName ("Code"); this.Property (t => t.Name) .HasColumnName ("FirstName"); this.Property (t => t.Family) .HasColumnName ("LastName"); MappedColumn 이름을 가져 오는 방법이 있습니까? 예 : PersonMap map = new PersonMap(); var pr = map.Property (p => p.Name); 문자열 columnName = pr.HasColumnName; // FirstName을 찾으십시오 – Saber

+0

@Saber. 이것은 확장 가능한 솔루션이 아닙니다. – Stumblor

관련 문제