0
public class AddressEntityMapper : EntityTypeConfiguration<AddressEntity>
{
public AddressEntityMapper()
{
ToTable("Address");
HasKey(m => m.AddressID);
HasRequired(m => m.UserEntity).WithMany(b => b.AddressEntity);
Property(p => p.AddressKey).HasColumnName("ADDRESSID");
Property(p => p.UserID).HasColumnName("User_id");
Property(p => p.Address1).HasColumnName("ADDRESS1");
Property(p => p.Address2).HasColumnName("ADDRESS2");
Property(p => p.Address3).HasColumnName("ADDRESS3");
Property(p => p.City).HasColumnName("CITY");
Property(p => p.State).HasColumnName("STATE");
Property(p => p.ZipCode).HasColumnName("ZIPCODE");
}
}
그리고 사용자 매퍼 :
public class UserEntityMapper : EntityTypeConfiguration<UserEntity>
{
public UserEntityMapper()
{
ToTable("User");
HasKey(m => m.UserID);
Property(p => p.UserID).HasColumnName("UserID");
Property(p => p.FirstName).HasColumnName("FIRSTNAME");
Property(p => p.LastName).HasColumnName("LAST_NAME");
Property(p => p.MiddleInitial).HasColumnName("MIDDLEINITIAL");
}
}
public class ProjectEntities : DbContext
{
public ProjectEntities()
: base("name=ProjectEntities ")
{
}
public DbSet<UserEntity> UserEntity { get; set; }
public DbSet<AddressEntity> AddressEntity { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new UserEntityMapper());
modelBuilder.Configurations.Add(new AddressEntityMapper());
}
}
그리고 매퍼로 delacred된다
이 물건은 잘 작동합니다. 이제 정보를 얻기 위해 로직을 변경해야합니다. 이제 회사는 완전한 사용자 정보를 얻기 위해 sql보기를 사용하기로 결정 했으므로 사용자의 모든 정보를 한 곳에서 얻을 수 있습니다. 이제는 재실행/모든 필드를 매핑하는 다른 매퍼를 만들지 않아도됩니다. 두 테이블 모두 SQL 뷰에서 가져옵니다.
public class UserFullEntityMapper : EntityTypeConfiguration<UserEntity, AddressEntity>
{
public UserFullEntityMapper()
{
ToTable("vw_user");
///Declare the auto mapping here to the fields from above entities to columns retuned from sql view.
}
}
제안하십시오 :
그래서 제 질문은 우리가 이러한 매퍼의 두 매핑 다른 매퍼를 선언 할 수있다. 감사
당신은 당신의보기의 새로운 엔티티를 정의해야