0

我发现了很多主题,但我不能在我的测试中做 hasMany,我有:

public class ProductModel
{
    public virtual Guid Id { get; set; }
    public virtual string ProductName { get; set; }
    public virtual IList<LicenseModel> License { get; set; }

    public ProductModel()
    {
        License = new List<LicenseModel>();
    }
}
public class LicenseModel
{
    public virtual Guid Id { get; set; }
    public virtual double Price { get; set; }
    public virtual string Period { get; set; }
    public virtual int Discount { get; set; }
    public virtual ProductModel ProductModel { get; set; }
}

还有一些映射尝试:

public class ProductMap: ClassMap<ProductModel>
    {
        public ProductMap() 
        {
            Id(x => x.Id);
            Map(x => x.ProductName);
            HasMany<LicenseModel>(x => x.License)
                .KeyColumn("Id");
            Table("Product");
        }
    }
public class LicenseMap: ClassMap<LicenseModel>
{
    public LicenseMap()
    {
        Id(x => x.Id);
        Map(x => x.Period);
        Map(x => x.Price);
        Map(x => x.Discount);
        References(x => x.ProductModel)
            .Class<ProductModel>()
            .Columns("LicenseId");
        Table("License");
    }
}

这样我的基地看起来像这样:

表产品看起来不太酷 :( 一些想法?感谢您的建议。

4

1 回答 1

0

我认为这些映射会帮助你

public class ProductMap : ClassMap<ProductModel>
{
    public ProductMap()
    {
        Table("Product");
        Id(x => x.Id);
        Map(x => x.ProductName);
        HasMany<LicenseModel>(x => x.License)
            .Inverse()
            .KeyColumn("ProductModelId");
    }
}

public class LicenseMap : ClassMap<LicenseModel>
{
    public LicenseMap()
    {
        Table("License");
        Id(x => x.Id);
        Map(x => x.Period);
        Map(x => x.Price);
        Map(x => x.Discount);
        References<ProductModel>(x => x.ProductModel)
            .Column("ProductModelId");
    }
}
于 2013-10-16T21:43:34.627 回答