問い合わせを行う顧客がいる場合 (問い合わせは 1 回のみ許可されます)、次のことを行いますか?
public class Customer
{
public string Name {get;set;}
public string ContactNumber {get;set;}
public virtual Inquiry Inquiry {get;set;}
}
public class Inquiry
{
public string Product {get;set;}
public string Information {get;set;}
public string Reason {get;set;}
}
または私はこのように持っていますか:
public class Customer
{
public string Name {get;set;}
public string ContactNumber {get;set;}
}
public class Inquiry
{
public string Product {get;set;}
public string Information {get;set;}
public string Reason {get;set;}
public virtual Contact Contact {get;set;}
}
最初のシナリオでは、ナビゲーション プロパティと同様に使用しない限り、Inquiryが削除された場合も削除されると確信しています。このシナリオはより理にかなっています。Customerpublic Guid? InquiryId {get;set;}
Customer2 番目のシナリオでは、aが削除された場合Inquiry、望ましい効果であると確信しています。customer => inquiryただし、顧客が行った問い合わせではなく、顧客が行った問い合わせを確認する必要があるため、ナビゲーション プロパティが少し冗長になりますinquiry.FirstOrDefault(x => x.Customer.Id.Equals(customerId))。
ある意味ではDelete On Cascadeプロパティは役立ちますが、ナビゲーション プロパティは冗長ですが、別の方法でDelete On Cascadeは役に立ちません (そして、それを有利に動作させるにはより多くのコードが必要です) が、ナビゲーション プロパティは役立ちます。
では、どのように進路を決めるのでしょうか。
最初のシナリオのもう1つの欠点は、関連するものを手動で削除する必要があることです。これは、カスケードInquiryを削除するCustomerとカスケードが無視されるためです(コードでオフになっているため)。