臭名昭着:这个SqlParameterCollection的索引n无效,Count =

cs0*_*815 16 nhibernate lucene.net hibernate

这个例外:

具有Count =的此SqlParameterCollection的索引n无效

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

我似乎已经发现了这个问题.我介绍了这个:

[DocumentId]
public virtual int GI
{
    get { return base.Id; }
    protected set { base.Id = value; }
} 
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

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");
        }
    }
Run Code Online (Sandbox Code Playgroud)

Rip*_*ppo 49

答案是: -

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

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

要验证这一点,因为您正在使用流畅和自动化,您需要查看XML映射.请参见[link] [2]并使用ExportTo(..)方法.完成后XML,查看是否有任何重复的属性,甚至是重复的映射文件.

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

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

<property name="GI" ...>
  <column name="GI" />
</property>
Run Code Online (Sandbox Code Playgroud)

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


use*_*426 5

完全归功于@Rippo,在 Fluent NHibernate 中帮助我的等效答案是:

对于课程:

public class User
{
   public virtual Department {get; set;}
}

public class Department
{
   public virtual ICollection<User> Users {get; set;}
}
Run Code Online (Sandbox Code Playgroud)

如果您有User实体的以下映射:

//Problem mapping
Map(x => x.DepartmentId)          
References(x => x.Department)
   .Column("Id")
   .ForeignKey("DepartmentId")
   .Fetch.Join();
Run Code Online (Sandbox Code Playgroud)

以下是可能的解决方案之一(由于one-to-many部分 -中的双重映射one-Department-to-many-Users):

// !Solution
Map(x => x.DepartmentId)          
References(x => x.Department)
   .Column("Id")
   .ForeignKey("DepartmentId")
   .Fetch.Join()
   .Not.Insert()   // <- added this
   .Not.Update();  // <- and this
Run Code Online (Sandbox Code Playgroud)