三元协会(第四纪?)扭曲

时间:2015-02-13 18:12:24

标签: c# nhibernate fluent-nhibernate nhibernate-mapping fluent-nhibernate-mapping

在阅读许多的映射条目后,我仍然没有找到一个清楚说明如何用Fluent nHibernate表示三元关联的方法。我对nHibernate还是比较新的,所以我可能会遗漏一些明显的东西。到目前为止,这是我的课程:

class Publisher
{
    private readonly IList<Book> _books = new List<Book>();
    private readonly IList<BookStore> _bookStores = new List<BookStore>();
    private readonly IList<IndividualPricing> _individualPricing = new List<IndividualPricing>();
    private readonly IList<BulkPricing> _bulkPricing = new List<BulkPricing>();

    public long? PublisherId { get; set; }
    public string PublisherName { get; set; }
    public string PrimaryContact { get; set; }

    public virtual IList<Book> Books
    {
        get { return _books; }
    }

    public virtual IList<BookStore> BookStores
    {
        get { return _bookStores; }
    }

    public virtual IList<IndividualPricing> IndividualPricing
    {
       get { return _individualPricing; }
    }

    public virtual IList<BulkPricing> BulkPricing
    {
       get { return _bulkPricing; }
    }
}

class Book
{
    public long BookId { get; set; }
    public string Title { get; set; }
    public string Author { get; set; }
    public decimal CoverPrice { get; set; }

    // ILists?
}

class BookStore
{
    public long BookStoreId { get; set; }
    public string Name { get; set; }
    public string PrimaryContact { get; set; }

    // ILists?
}

class IndividualPricing
{
    public long PricingId { get; set; }
    public long PublisherId { get; set; }
    public long BookId { get; set; }
    public long BookStoreId { get; set; }
    public decimal? CustomPricing { get; set; }
    public decimal? DiscountPct { get; set; }

    // ILists?
}

class BulkPricing
{
    public long PricingId { get; set; }
    public long PublisherId { get; set; }
    public long BookStoreId { get; set; }
    public decimal DiscountPct { get; set; }

    // ILists?
}

public PublisherMap()
{
    Id(x => x.PublisherId);
    Map(x => x.PublisherName).Not.Nullable();
    Map(x => x.PrimaryContact).Not.Nullable();

    // .References?
    // .HasOneToMany?
    // .HasManyToMany?
}

public BookMap()
{
    Id(x => x.BookId);
    Map(x => x.Title).Not.Nullable();
    Map(x => x.Author).Not.Nullable();
    Map(x => x.CoverPrice).Not.Nullable();

    // .References?
    // .HasOneToMany?
    // .HasManyToMany?
}

public BookStoreMap()
{
    Id(x => x.BookStoreId);
    Map(x => x.Name).Not.Nullable();
    Map(x => x.PrimaryContact).Not.Nullable();

    // .References?
    // .HasOneToMany?
    // .HasManyToMany?
}

public BulkPricingMap()
{
    Id(x => x.PricingId);
    Map(x => x.PublisherId).Not.Nullable();
    Map(x => x.BookStoreId).Not.Nullable();
    Map(x => x.DiscountPct).Not.Nullable();

    // .References?
    // .HasOneToMany?
    // .HasManyToMany?
}

public IndividualPricingMap()
{
    Id(x => x.PricingId);
    Map(x => x.PublisherId).Not.Nullable();
    Map(x => x.BookStoreId).Not.Nullable();
    Map(x => x.BookId).Not.Nullable();
    Map(x => x.CustomPricing).Nullable();
    Map(x => x.DiscountPct).Nullable();

    // .References?
    // .HasOneToMany?
    // .HasManyToMany?
}

正如您所看到的,我不确定哪些关系会在Fluent中出现。显然要获得具体的定价,我要求出版商+书店+书籍,看看是否有“特价”,只是出版商+书店,看看是否有“一揽子交易”,只是出版商+书籍,以获得保障价格。我可以处理查询部分;)

我只是需要一些帮助才能将Fluent映射排除在外。比简单的一对多或多多关系复杂一点,其中有很多例子。

我希望对来自任何特定入口点Publisher,Bookstore或Book的查询保持开放态度。甚至可能询问“谁有谁从谁那里得到什么特价?” (由定价表驱动)。

感谢。

0 个答案:

没有答案