2012-03-29 24 views
6

anda şöyle görünür:Varlık Framework - Yeniden Kompleks Tip I Kod İlk Varlık çerçevesinde bir Varlık var

public class Location 
{ 
    public string Department { get; set; } 
    public string Queue { get; set; } 
} 
: Böyle bir şey olarak bu tip Kompleks Tipi oluşturmak istiyorum
public class Entity 
{ 
    // snip ... 

    public string OriginalDepartment { get; set; } 
    public string OriginalQueue { get; set; } 

    public string CurrentDepartment { get; set; } 
    public string CurrentQueue { get; set; } 
} 

public Location Original { get; set; } 
public Location Current { get; set; } 

bu mümkün mü, yoksa yapın:

ben hem Akım ve Orijinal için bu aynı tür kullanmak istiyorum CurrentLocation ve OriginalLocation iki karmaşık tür oluşturmalıyım? Bu kutunun dışında desteklenir

public class OriginalLocation 
{ 
    public string Department { get; set; } 
    public string Queue { get; set; } 
} 

public class CurrentLocation 
{ 
    public string Department { get; set; } 
    public string Queue { get; set; } 
} 

cevap

7

, iki karmaşık türleri oluşturmak için gerek yoktur. Sütun adlarını özelleştirmek için

modelBuilder.ComplexType<Location>(); 

Ayrıca bu myCustomName sütunda

için MyEntity.Current.Queue eşler ana birimi konfigürasyonları

public class Location 
{ 
    public string Department { get; set; } 
    public string Queue { get; set; } 
} 

public class MyEntity 
{ 
    public int Id { get; set; } 
    public Location Original { get; set; } 
    public Location Current { get; set; } 
} 

public class MyDbContext : DbContext 
{ 
    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     modelBuilder.ComplexType<Location>(); 

     modelBuilder.Entity<MyEntity>().Property(x => x.Current.Queue).HasColumnName("myCustomColumnName"); 
    } 
} 

onları yapılandırmanız gerekir, model oluşturucu ile explicitely sizin karmaşık türlerini yapılandırabilirsiniz

+0

Sanırım kutudan nasıl desteklendiğinden emin değilim. ComplexTypeConfiguration 'sınıfında, bir sütun adı belirtmemi isteyen bir' Property() 'yöntemi vardır. Sütun adı her biri için farklı olacak – Dismissile

+0

Sanırım her iki karmaşık tür için sütun isimlerini özelleştirmek mümkün olmasını açıklığa kavuşturmalıyım. Bu destekleniyor mu? – Dismissile

+0

Onları yalnızca farklı bir önek mi yoksa tamamen özelleştirilmiş mi yapmak istiyorsunuz? – archil