24

Bu yinelenen olarak işaretlenmeden önce, diğer ilgili yayınları işaretledim ve sorumu yanıtlamıyorlar.varlık çerçevesindeki tek bir varlık sınıfına birden çok tablo eşleme

1: 1 ilişkisine sahip 2 tablo içeren eski bir veritabanında çalışıyorum. Şu anda, bu tabloların her biri için tanımlı olan için bir tür (1 Test: 1 Sonuç) tek bir sınıfa birleştirmek istiyorum.

akım türleri Ben şu anda bizim eski Oracle veritabanına bu haritalama için akıcı API kullanıyorum bu

public class TestResult 
{ 
    public   int  Id    { get; set; } 
    public   string  Status   { get; set; } 
    public   string  Analysis  { get; set; } 
    public   string  ComponentList { get; set; } 
    public   string  TestName  { get; set; } 
    public   string  Text   { get; set; } 
    public   string  Units   { get; set; } 
    public   bool  OutOfRange  { get; set; } 
    public   string  Status   { get; set; } 
    public   string  Minimum   { get; set; } 
    public   string  Maximum   { get; set; } 

    public virtual Instrument InstrumentUsed { get; set; } 
} 

gibi görünmek için onları tercih ediyorum bu

public class Result 
{ 
    public   string  Id     { get; set; } 
    public   string  Name    { get; set; } 
    public   string  Text    { get; set; } 
    public   string  Units    { get; set; } 
    public   bool  OutOfRange   { get; set; } 
    public   string  Status    { get; set; } 
    public   string  Minimum    { get; set; } 
    public   string  Maximum    { get; set; } 

    public virtual Instrument InstrumentUsed  { get; set; } 

    public virtual Test  ForTest    { get; set; } 
} 


public class Test 
{ 
    public   int  Id   { get; set; } 
    public   string Status  { get; set; } 
    public   string Analysis  { get; set; } 
    public   string ComponentList { get; set; } 
    public virtual Sample ForSample  { get; set; } 
    public virtual Result TestResult { get; set; } 
} 

benziyor.

Bunları tek bir sınıfa birleştirmenin en iyi yöntemi ne olurdu? Lütfen bunun eski bir veritabanı olduğunu unutmayın. Tabloların değiştirilmesi bir seçenek değildir ve görüşlerin oluşturulması projenin bu noktasında uygulanabilir bir çözüm değildir.

cevap

31

Her iki tabloda da aynı birincil anahtara sahipseniz, bunu elde etmek için Varlık Bölme'yi kullanabilirsiniz.

modelBuilder.Entity<TestResult>() 
    .Map(m => 
     { 
     m.Properties(t => new { t.Name, t.Text, t.Units /*other props*/ }); 
     m.ToTable("Result"); 
     }) 
    .Map(m => 
     { 
     m.Properties(t => new { t.Status, t.Analysis /*other props*/}); 
     m.ToTable("Test"); 
     }); 

İşte yararlı bir article

+1

bu ayrı haritalama ilişkisi ile onlar hala mümkün olacağını yoktu durumunda işe veya henüz çerçevesinde bu sürümünde olduğu mevcut değildir bu yüzden aynı anahtarı var ? –

+0

Enstrüman ile nasıl eşleşirsiniz? – roland

İlgili konular