本文介绍了臭名昭著:具有Count =的此SqlParameterCollection的无效索引n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此例外:

此SqlParameterCollection的无效索引n为Count =

Invalid index n for this SqlParameterCollection with Count=

通常指向重复的映射信息(请参见Stack Overflow + Google).我很确定我没有.还有其他原因吗?

Usually points at duplicate mapping information (see Stack Overflow + Google). I am pretty sure I have none. Are there any other reasons for it?

我似乎已经确定了问题所在.我介绍了这个:

I seem to have identified the problem. I introduced this:

[DocumentId]
public virtual int GI
{
    get { return base.Id; }
    protected set { base.Id = value; }
}

要通过lucene.net使用搜索.这似乎会干扰FNH!我在这里有什么选择?

To use search via lucene.net. This seems to interfere with FNH! What are my options here?

PS:

at System.Data.SqlClient.SqlParameterCollection.RangeCheck(Int32 index)
   at System.Data.SqlClient.SqlParameterCollection.GetParameter(Int32 index)
   at System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32 index)
   at NHibernate.Type.Int32Type.Set(IDbCommand rs, Object value, Int32 index)
   at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index)
   at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object value, Int32 index, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, IDbCommand statement, ISessionImplementor session, Int32 index)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
   at NHibernate.Action.EntityInsertAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
   at NHibernate.Engine.ActionQueue.ExecuteActions()
   at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
   at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
   at NHibernate.Impl.SessionImpl.Flush()
   at SharpArch.Data.NHibernate.DbContext.CommitChanges()
   at Updater1.Program.Main(String[] args) in C:\Users\bla\Documents\Visual Studio 2010\Projects\Bla\Updater1\Program.cs:line 97

PPS:

public class MappedSequenceMap : IAutoMappingOverride<MappedSequence>
    {
        public void Override(AutoMapping<MappedSequence> mapping)
        {
            mapping.Id(x => x.Id, "GI").GeneratedBy.Assigned();

            mapping.Map(x => x.Affiliation).Length(10000);
            mapping.Map(x => x.Gene).Length(10000);
            mapping.Map(x => x.OriginalIsolationCountry).Length(10000);
            mapping.Map(x => x.OriginalAffiliation).Length(10000);
            mapping.Map(x => x.PMIDs).Length(10000);
            mapping.Map(x => x.Product).Length(10000);
            mapping.Map(x => x.Fasta).Length(10000);
            mapping.Map(x => x.Note).Length(10000);
            mapping.Map(x => x.Strain).Length(10000);

            mapping.HasManyToMany(x => x.PubmedPublications).Table("SequencesPubmedPublications");
        }
    }

推荐答案

答案是:-

a)您在相同的类中映射了一个重复的属性

a) you have a duplicate property mapped in the same class

b)可以将外键以及对映射文件中的相关实体使用<many-to-one ...公开.如果是这种情况,请在外键属性中添加insert="false" and update="false"并再次运行.

b) It is possible if you are exposing a foreign-key as well as using a <many-to-one ... to the related entity in the mapping file. If this is the case add insert="false" and update="false" to the foreign key property and run again.

要验证这一点,当您使用流利和自动映射时,您需要查看XML映射.参见此[link] [2],并使用ExportTo(..)方法.完成此操作后,请查看XML并查看是否具有重复的属性,甚至重复的映射文件.

To verify this, as you are using fluent and automapping, you need to look at the XML mappings. See this [link][2] and use ExportTo(..) method. Once you have done this look at the XML and see if you have any duplicate properties OR even duplicate mapping files.

在这种情况下,您有两个对GI列的引用:

In you case, you have two references to column GI:

<id name="Id" ...>
  <column name="GI" />
  <generator class="assigned" />
</id>

<property name="GI" ...>
  <column name="GI" />
</property>

我认为您不能在Id类属性上设置注释[DocumentId].我认为您可能需要放弃此类的自动映射,并通过流畅的手动配置!

I take it you can't set the annotation [DocumentId] on the Id class property. I think you may need to abandon auto mapping for this class and configure via fluent manually!

这篇关于臭名昭著:具有Count =的此SqlParameterCollection的无效索引n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:30