NHibernate.MappingException : No persister for: System.Int32

陌路散爱 提交于 2019-12-11 09:50:31

问题


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:


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.



来源:https://stackoverflow.com/questions/11397669/nhibernate-mappingexception-no-persister-for-system-int32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!