Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在NHidernate中将嵌套对象展平为一行_C#_Nhibernate_Nhibernate Mapping - Fatal编程技术网

C# 在NHidernate中将嵌套对象展平为一行

C# 在NHidernate中将嵌套对象展平为一行,c#,nhibernate,nhibernate-mapping,C#,Nhibernate,Nhibernate Mapping,我将一个类嵌套在另一个类中: 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; } publ

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

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
为空

如何创建此映射?

使用组件

Property(x => x.OuterProp1);
Property(x => x.OuterProp2);
Component(
    x => x.InnerClass,
    comp =>
    {
        comp.Property(x => x.InnerProp1);
        comp.Property(x => x.InnerProp2);
    });

public virutal string
所有道具都必须是VirtualTanks,这让我克服了大部分问题,但当我尝试从表中加载时,内部类为null。好的,如果我将InerClass设为虚拟类,它就会被创建@wudzik的评论对此很有帮助。对不起,事实证明我不需要它是虚拟的。