1
public class Parent
{
public virtual field1 { get; set;}
public virtual field2 { get; set;}
public virtual Child { get; set;
}

public class Child
{
public virtual childfield1 { get; set;} //composite primary key
public virtual childfield2 { get; set;} //composite primary key
public string somedescription { get; set;}
}

1 つのフィールドだけをマップする必要がある場合は、Parent マップ クラスで以下を実行できます。

References(x => x.Child).ForeignKey("field1");

フィールド 1 とフィールド 2 の 2 つのキーで結合する必要がある場合、どうすればよいですか?

4

1 に答える 1

2
public class Parent
{
    public virtual Child Child { get; set; }
}

public class Child
{
    public virtual int Key1 { get; set; } //composite primary key
    public virtual int Key2 { get; set; } //composite primary key
    public virtual string SomeDescription { get; set;}
}

// in ParentMap
References(p => p.Child).Columns.Add("child_key1", "child_key2");

// in Child
CompositeId()
    .KeyProperty(x => x.Key1)
    .KeyProperty(x => x.Key2);

子をロードせずに ChildKey1 (列) にアクセスする

var key1 = parent.Child.Key1;
于 2012-12-11T12:41:12.493 に答える