Nhibernate ArgumentOutOfRangeException:索引超出范围

Nhibernate ArgumentOutOfRangeException:索引超出范围,nhibernate,fluent-nhibernate,Nhibernate,Fluent Nhibernate,每当我使用 用于验证具有 对值对象的引用 public class CatalogItem : DomainEntity { internal virtual Manufacturer Manufacturer { get; private set; } internal virtual String Name { get; private set; } protected CatalogItem() {}

每当我使用 用于验证具有 对值对象的引用

    public class CatalogItem : DomainEntity
    {
        internal virtual Manufacturer Manufacturer { get; private
set; }
        internal virtual String Name { get; private set; }

        protected CatalogItem()
        {}

        public CatalogItem(String name, String manufacturer)
        {
            Name = name;
            Manufacturer = new Manufacturer(manufacturer);
        }
    }

    public class CatalogItemMapping : ClassMap<CatalogItem>
    {
        public CatalogItemMapping()
        {
            Id(catalogItem => catalogItem.Id);

            Component<Manufacturer>(category => category.Manufacturer,
                                    m => m.Map(manufacturer =>
manufacturer.Name));

            Map(catalogItem => catalogItem.Name);
            Map(Reveal.Property<CatalogItem>("Price"));
        }
    }

    [TestFixture]
    public class When_verifying_the_class_mapping_of_a_catalog_item
        : NHibernateSpecification
    {
        [Test]
        public void Then_a_catalog_object_should_be_persistable()
        {
            new PersistenceSpecification<CatalogItem>(Session)
                .VerifyTheMappings();
        }
    }

    [TestFixture]
    public class NHibernateSpecification
        : Specification
    {
        protected ISession Session { get; private set; }

        protected override void Establish_context()
        {
            var configuration = new SQLiteConfiguration()
                .InMemory()
                .ShowSql()
                .ToProperties();

            var sessionSource = new SessionSource(configuration, new
RetailerPersistenceModel());
            Session = sessionSource.CreateSession();

            sessionSource.BuildSchema(Session);
            ProvideInitialData(Session);

            Session.Flush();
            Session.Clear();
        }

        protected override void Dispose_context()
        {
            Session.Dispose();
            Session = null;
        }

        protected virtual void ProvideInitialData(ISession session)
        {}
    }
公共类CatalogItem:DomainEntity
{
内部虚拟制造商制造商{get;私有
集合;}
内部虚拟字符串名称{get;private set;}
受保护的CatalogItem()
{}
公共CatalogItem(字符串名称、字符串制造商)
{
名称=名称;
制造商=新制造商(制造商);
}
}
公共类CatalogItemMapping:ClassMap
{
公共CatalogItemMapping()
{
Id(catalogItem=>catalogItem.Id);
组件(类别=>类别制造商,
m=>m.Map(制造商=>
制造商名称);
映射(catalogItem=>catalogItem.Name);
地图(显示财产(“价格”);
}
}
[测试夹具]
验证目录项的映射时的公共类
:NHibernateSpecification
{
[测试]
public void那么目录对象应该是持久的()
{
新PersistenceSpecification(会话)
.验证应用程序();
}
}
[测试夹具]
公共类NHibernateSpecification
:规格
{
受保护的ISession会话{get;private set;}
受保护的覆盖无效建立上下文()
{
var配置=新的SQLiteConfiguration()
.InMemory()
.ShowSql()
.ToProperties();
var sessionSource=新sessionSource(配置,新
RetailerPersistenceModel());
Session=sessionSource.CreateSession();
sessionSource.BuildSchema(会话);
提供初始数据(会议);
Session.Flush();
Session.Clear();
}
受保护的覆盖void Dispose_context()
{
Session.Dispose();
会话=空;
}
受保护的虚拟空间提供初始数据(ISession会话)
{}
}
下面是我得到的错误:

测试用例 “那么目录对象应该是持久的”不执行: System.ArgumentOutOfRange异常: 索引超出范围。必须是 非负数且小于 收藏。参数名称:索引 at System.THROWHERPER.ThrowArgumentOutOfRangeException (辩论论点除外, 例外情况(资源) 在System.ThrowHelper.throwargumentotofrangeexception()中 在System.Collections.Generic.List
1.get\u项(Int32
索引)
在System.Data.SQLite.SQLiteParameterCollection.GetParameter(Int32
索引)
位于System.Data.Common.DbParameterCollection.System.Collections.IList.get_项
(Int32索引)
在NHibernate.Type.GuidType.Set(IDB命令
cmd,对象值,Int32索引)
在NHibernate.Type.NullableType.NullSafeSet处(IDB命令
cmd,对象值,Int32索引)
在NHibernate.Type.NullableType.NullSafeSet处(IDB命令
st,对象值,Int32索引,
iSession(实施者会话)
在NHibernate.Persister.Entity.AbstractEntityPersister.Deterhemate
(对象id,对象[]字段,对象
rowId,布尔[]includeProperty,
布尔[][]包括分栏,Int32
表,IDbCommand语句,
ISessionImplementor会话,Int32
索引)
位于NHibernate.Persister.Entity.AbstractEntityPersister.Insert(对象
id,对象[]字段,布尔值[]
notNull、Int32 j、SqlCommandInfo sql、,
对象对象,ISessionImplementor
(会议)
位于NHibernate.Persister.Entity.AbstractEntityPersister.Insert(对象
id,对象[]字段,对象obj,
iSession(实施者会话)
在NHibernate.Action.EntityInsertAction.Execute()处
在NHibernate.Engine.ActionQueue.Execute(IExecutable)中
可执行文件)
在NHibernate.Engine.ActionQueue.ExecuteActions(IList
(列表)
在NHibernate.Engine.ActionQueue.ExecuteActions()处
在NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions
(IEventSource会话)
在NHibernate.Event.Default.DefaultFlushEventListener.OnFlush
(FlushEvent事件)
在NHibernate.Impl.SessionImpl.Flush()处
在NHibernate.Transaction.AdoTransaction.Commit()处
d:\Builds\FluentNH\src\FluentNHibernate\Testing
\PersistenceSpecification.cs(127,0):
在
FluentNHibernate.Testing.PersistenceSpecification
1.TransactionalSave (对象属性值) d:\Builds\FluentNH\src\FluentNHibernate\Testing \PersistenceSpecification.cs(105,0): 在 FluentNHibernate.试验.持久性规范'1.验证应用 () C:\Source\SupplyChain\Tests\Retailer.IntegrationTests\Mappings \CatalogItemMappingSpecifications.cs(14,0): 在 SupplyChain.Retailer.IntegrationTests.Mappings.When\u验证\u目录\u项的\u类\u映射\u时,则\u目录\u对象\u应\u是持久的 ()

很抱歉发了这么长的帖子,但这篇文章让我忙了好几天 几个小时了。这可能不是FNH造成的,因为我找到了这张JIRA票 NH本身也提到了类似的东西:

我仍然希望我的代码中有错误:-)。任何 思想


提前感谢

您的
目录项
似乎没有
价格
属性,这在您使用
显示
帮助程序时显得很奇怪。

是的,我删除了该属性以减少一些噪音。我想我也忘了从映射中删除它。在做了更多的调查之后,我注意到这与将制造商映射为组件有关。当我使用一个普通的旧字符串而不是一个单独的类时,一切都很好。

我找到了这个问题的解决方案,它是由我自己的 首先是愚蠢。它是一个
<class name="CatalogItem" table="`CatalogItem`" xmlns="urn:nhibernate-
mapping-2.2" optimistic-lock="version">
    ...

    <property name="Name" length="100" type="String">
      <column name="Name" />
    </property>

    ...

    <component name="Manufacturer" insert="false" update="true">
      <property name="Name" length="100" type="String">
        <column name="Name" />
      </property>
    </component>
  </class>