0

我有一个嵌套在另一个类中:

public class InnerClass
{
    public string InnerProp1 { get; set; }
    public string InnerProp2 { get; set; }
}

public class OuterClass
{
    public string OuterProp1 { get; set; }
    public string OuterProp2 { get; set; }
    public InnerObject InnerClass { get; set; }
}

我想将它映射到这张表:

CREATE TABLE FlatTable
(
    OuterProp1 VARCHAR(20),
    OuterProp2 VARCHAR(20),
    InnerProp1 VARCHAR(20),
    InnerProp2 VARCHAR(20),
)

我尝试了一个天真的映射

Property(x => x.OuterProp1);
Property(x => x.OuterProp2);
Property(x => x.InnerObject.InnerProp1);
Property(x => x.InnerObject.InnerProp2);

这失败了ArgumentNullException,我怀疑是由于为x.InnerObject空。

如何创建此映射?

4

1 回答 1

2

使用组件

Property(x => x.OuterProp1);
Property(x => x.OuterProp2);
Component(
    x => x.InnerClass,
    comp =>
    {
        comp.Property(x => x.InnerProp1);
        comp.Property(x => x.InnerProp2);
    });
于 2013-10-23T06:29:08.427 回答