3

我正在使用以下映射配置将我的值对象项映射为组件

{
            Table("Product");
            Not.LazyLoad();
            Id(x => x.Id, "id");
            Map(x => x.Number, "number");
            Map(x => x.Name, "name");
            Map(x => x.Description, "description");
            Map(x => x.Status, "status");
            HasMany(x => x.ItemLines).Component(
                m =>
                {                                                                               
                        m.Map(x => x.ItemId, "itemid");
                        m.Map(x => x.Qty, "quantity");                      
                    }).Table("productitems").KeyColumn("itemid");
        }

Class structure 


public class ItemLine 
{
    public Product Product { get; set; }
    public Guid ItemId { get; set; }
    public int Qty { get; set; }




    public ItemLine()
    {

    }
    public ItemLine(Product product, Guid itemId, int qty)
    {
        Product = product;
        ItemId = itemId;
        Qty = qty;

    }

//Equality and GetHashCode implemented.....


}

我能够将数据插入数据库,但在通过产品 ID 检索时,项目行中的产品属性为空。

我是否需要在映射中传递任何引用>

请帮忙

谢谢,

三月

4

1 回答 1

6

行。通过反复试验解决。

添加 m.ParentReference(x => x.Product);

{ 
            Table("Product"); 
            Not.LazyLoad(); 
            Id(x => x.Id, "id"); 
            Map(x => x.Number, "number"); 
            Map(x => x.Name, "name"); 
            Map(x => x.Description, "description"); 
            Map(x => x.Status, "status"); 
            HasMany(x => x.ItemLines).Component( 
                m => 
                {                                                                                
                        m.Map(x => x.ItemId, "itemid"); 
                        m.Map(x => x.Qty, "quantity");

                        m.ParentReference(x => x.Product);   


                    }).Table("productitems").KeyColumn("itemid"); 
        } 

希望这可以帮助某人。

于 2010-10-31T18:15:50.823 回答