エンティティでコードの最初のメソッドを使用すると、単一の外部キーに関連付けられた複数の関係を確立できますか?例えばEntity Framework 4.1コードファースト - 複数の関係を持つ外部キー?
、私は次のクラスを持っていると言う:
public class BuzzItem
{
public int BuzzItemID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
// Collection of Comments posted about this BuzzItem (FOREIGN KEY)
public virtual ICollection<Comment> Comments { get; set; }
}
public class Merchant
{
public int MerchantID { get; set; }
public string Name { get; set; }
// Collection of Comments posted about this Merchant (FOREIGN KEY)
public virtual ICollection<Comment> Comments { get; set; }
}
public class Comment
{
public int CommentID { get; set; }
public string Comment { get; set; }
// These would both be a FOREIGN KEY to their respectivate tables
public virtual BuzzItem BuzzItemID { get; set; }
public virtual Merchant UserID { get; set; }
}
は二重の関係を確立し、BuzzItemや商人のオブジェクトのいずれかを受け入れることができる単一の変数を持つ2つの外部キーの変数を交換することが可能です関係のために?
私はこのサンプルを簡潔にするためにスクラップから作成しました。だから、私のコードにミスがあったらお詫びしますが、達成しようとしていることの一般的な考え方はうまくいけば分かります。
代わりに、次のようなものを試すことは可能でしょうか? 'public virtual int SourceID {get;セット; } 'を呼び出して、RTTIを使用してBuzzItemオブジェクトまたはMerchantオブジェクトにキャストしますか?もしそうなら、それをどうやって実装するかについてのヒントはありますか? –