Płynne problemy z utrwalaniem kolekcji dzieci w NHibernate

Mam następujące klasy mapowania (skopiowano tylko odpowiednią część):

public class CardTemplateMapping : ClassMap<CardTemplate>
{
    public CardTemplateMapping()
    {
        Table("cardtemplate");

        Id(x => x.Id)
            .Column("id")
            .GeneratedBy.Native();

        HasMany(x => x.CostStructures)
            .KeyColumn("cardtemplate_id")
            .Cascade.All();

    }
}
public class CostStructureMapping : ClassMap<CostStructure>
{
    public CostStructureMapping()
    {
        Table("coststructure");

        Id(x => x.Id)
            .Column("id")
            .GeneratedBy.Native();

        References(x => x.CardTemplate)
            .Column("cardtemplate_id");

        HasMany(x => x.CostComponents)
            .KeyColumn("coststructure_id")
            .Cascade.AllDeleteOrphan();

    }
}
public class CostStructureComponentMapping : ClassMap<CostStructureComponent>
{
    public CostStructureComponentMapping()
    {
        Table("CostStructureComponent");

        Id(x => x.Id)
            .Column("id")
            .GeneratedBy.Native();

        References(x => x.CostStructure)
            .Column("coststructure_id");

        References(x => x.ResourceType)
            .Column("resourcetype_id");
    }
}

Nhibernate ładuje relacje tak, jak zamierzałem. Ale dwie części Mapowania wydają się nieco dziwne (albo to, albo moje oczekiwania są dziwne).

Pierwszy:

 CostStructure structure = new CostStructure() { CardTemplate = template };
 template.CostStructures.Add(structure);
 Session.Save(template);
 Session.Flush();

To nie zapisuje nowegoCostStructure instancja. Czemu?

Drugi: zakładając, że załadowałemCardTemplate mającyCostStructure zawierające trzyCostStructureComponent podmioty. Teraz chcę usunąć jedną z nichCostStructureComponents zCostStructure.
Próbowałem:

costStructure.CostComponents.Remove(component);
component.CostStructure = null;
session.Save(template)

Teraz wiem, że jawne usunięcie jawnie działa, ale nie powinnoDeleteOrphan część również zapewnia, że ​​komponent, teraz bezCostStructure do odwołania, jest usunięty? Zamiast tego NHibernate próbuje wykonać następującą aktualizację:

UPDATE CostStructureComponent 
SET amount = @p0, 
     coststructure_id = @p1, 
     resourcetype_id = @p2
WHERE id = @p3;

@p0 = 1 [Type: Int32 (0)], 
@p1 = NULL [Type: Int64 (0)], 
@p2 = 5 [Type: Int64 (0)], 
@p3 = 13 [Type: Int64 (0)]

Czy to możliwe, że Equals / GetHashCode zostały zaimplementowane w niewłaściwy sposób?

Przepraszam, jest późno, był długi dzień i tak dalej ... Jeśli mówię bełkot, daj mi znać ...

questionAnswers(1)

yourAnswerToTheQuestion