1
votes

I have the following...

public class TempCartMap : ClassMap<TempCart>
{
   Id(x => x.Id).GeneratedBy.Identity();
   ...
   HasMany(x => x.Products)
    .Inverse().Cascade.AllDeleteOrphan()
        .Table("tblCartProducts")
            .Element("ProductId").KeyColumn("CartId").AsBag();
}

[Serializable]
public class TempCart {

  public TempCart(){
    Products = new List<int>();
  }

  public virtual IList<int> Products { get; set; }

}

And a persistance specification:

    [Test]
    public void CanMapSaleCart()
    {
        SystemTime.Freeze();

        IList<int> list = new List<int> {1, 2, 3};

        new PersistenceSpecification<SaleCart>(Session)
                        //Other PropertyChecks that work fine without the Next check
                        .CheckList(x => x.AdditionalProducts, list)
                        .VerifyTheMappings();
            }

If I change the CheckList to CheckProperty I get

System.ApplicationException : For property 'Products' expected 'System.Collections.Generic.List1[System.Int32]' of type 'System.Collections.Generic.List1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' but got '' of type 'System.Collections.Generic.IList`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'

If I leave it CheckList I get

NHibernate.MappingException : No persister for: System.Int32

Driving me nuts!


--- Additional

If I remove .Inverse().Cascade.AllDeleteOrphan() and create a new test (not using persistence specification)

[Test]
public void CanMapSaleCartWithAdditionalProducts()
{
    SaleCart sCart = FactoryGirl.Build<SaleCart>();
    sCart.AdditionalProducts = new List<int> { 1, 2, 3 };

    Session.Save(sCart);
    FlushAndClear();
}

That saves as I'd expect it to, creating the sale cart then adding the products to the other table.

TLDR: This issue appears to be because I'm trying to use a persistence specification test on int, while the persistence specification test in fact only accepts Entitys by name (str). If anyone wants to expand on that, feel free.

1

1 Answers

2
votes

This issue appears to be because I'm trying to use a persistence specification test on int, while the persistence specification test in fact only accepts Entitys by name (str). If anyone wants to expand on that, feel free.