NHibernate.MappingException:没有persister:System.Int32 [英] NHibernate.MappingException : No persister for: System.Int32

查看:179
本文介绍了NHibernate.MappingException:没有persister:System.Int32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  public class TempCartMap:ClassMap< TempCart> 
{
Id(x => x.Id).GeneratedBy.Identity();
...
HasMany(x => x.Products)
.Inverse()。Cascade.AllDeleteOrphan()
.Table(tblCartProducts)
.Element( 产品编号)KeyColumn( CartId)AsBag()。;




$ b $ public b




$ ;
}

公共虚拟IList< int>产品{get;组; }






一个持久性规范:

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

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

新的PersistenceSpecification< SaleCart>(Session)
//其他的PropertyChecks工作正常,没有Next检查
.CheckList(x => x.AdditionalProducts,list)
.VerifyTheMappings();





如果将 CheckList 更改为 CheckProperty

我得到


System.ApplicationException:用于'产品'预期的
'System.Collections.Generic。 $ b $ System.Collections.Generic.List
1 [[System.Int32,mscorlib,
Version = $ List $ 1 [System.Int32] 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]]'
但是得到'类型'System.Collections.Generic.IList`1 [[System.Int32,
mscorlib,Version = 4.0。 0.0,Culture = neutral,
PublicKeyToken = b77a5c561934e089]]'


如果我将它保留 我得到


NHibernate.MappingException:没有persister for:System.Int32


驱使我坚果!




---附加

如果我删除.Inverse()。Cascade.AllDeleteOrphan()
并创建一个新的te st(不使用持久化规范)
$ b $ pre $ [Test]
public void CanMapSaleCartWithAdditionalProducts()
{
SaleCart sCart = FactoryGirl.Build< SaleCart>();
sCart.AdditionalProducts =新列表< int> {1,2,3};

Session.Save(sCart);
FlushAndClear();

$ / code>

这样可以节省我的预计时间,创建销售车然后添加该产品到另一个表。

TLDR
这个问题似乎是因为我试图在int上使用持久性规范测试,规范测试实际上只接受实体名称(str)。
如果有人想扩大这一点,感觉自由。

解决方案

这个问题似乎是因为我试图在int上使用持久性规范测试,而持久性规范测试实际上只通过名称(str)接受实体。如果有人想扩大,感觉自由。


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.

解决方案

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.

这篇关于NHibernate.MappingException:没有persister:System.Int32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆