Why do my Fluent NHibernate subclass mappings generate redundant columns?

I have the following objects

public abstract class Card
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual string Description { get; set; }

    public virtual Product Product { get; set; }
    public virtual Sprint Sprint { get; set; }
}
public class Story:Card
{
    public virtual double Points { get; set; }
    public virtual int Priority { get; set; }
}
public class Product
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }

    public virtual IList<Story> Stories { get; private set; }

    public Product()
    {
         Stories = new List<Story>();
    }
}

And the following displays

public class CardMap:ClassMap<Card>
{
    public CardMap()
    {
        Id(c => c.Id)
            .Index("Card_Id");

        Map(c => c.Name)
            .Length(50)
            .Not.Nullable();
        Map(c => c.Description)
            .Length(1024)
            .Not.Nullable();

        References(c=>c.Product)
            .Not.Nullable();

        References(c=>c.Sprint)
            .Nullable();

    }
}
public class StoryMap : SubclassMap<Story>
{
    public StoryMap()
    {
        Map(s => s.Points);
        Map(s => s.Priority);

    }
}
public class ProductMap:ClassMap<Product>
{
    public ProductMap()
    {
        Id(p => p.Id)
            .Index("Product_Id");

        Map(p => p.Name)
            .Length(50)
            .Not.Nullable();

        HasMany(p => p.Stories)
            .Inverse();
    }

When I create my schema, tables are created as follows

Card
---------
Id
Name
Description
Product_id
Sprint_id

Story
------------
Card_id
Points
Priority
Product_id
Sprint_id

I would expect to see Product_id and Sprint_id columns ONLY in the Card table, not in the Story table.

What am I doing wrong or misunderstanding?

+3
source share
2 answers

NB: tested only on NH2 project

, , , , , TL;DR , Product_id Spring_id Story redundant - HasMany(x => x.Stories) SpringMap ProductMap. CardMap References(x => x.Product References(x => x.Sprint).

, ProductMap.cs:24-25 SprintMap.cs:22 .

, , .

, , . , :

ProductMap.cs
        HasMany(p => p.Stories)
            .KeyColumn("ProductOwner_id")
            .Inverse();

SprintMap.cs
        HasMany(s => s.Stories)
            .KeyColumn("SprintOwner_id")
            ;

CardMap.cs
        References(c=>c.Product)
            .Column("Product_id")
            .Not.Nullable();

        References(c=>c.Sprint)
            .Column("Sprint_id")
            .Nullable();

, 1: N / "". , .

. , ( CardMap.cs) - - , Sprint_id SprintOwner_id. , - , - , , /nhibernates- , .

+1

, Story Card, , Product_Id Sprint_Id Story, Card.

, , NHibernate , . . NHibernate , , , - .

0

Source: https://habr.com/ru/post/1782120/


All Articles