English 中文(简体)
臭名昭著: 无效的 SqlParameter 与 计数 = 相重叠的无效索引 n
原标题:Infamous: Invalid index n for this SqlParameterCollection with Count=

这一例外:

对于此 SqlParater 和 count= 的 Collection 无效的 索引 n

通常地指出重复的绘图信息(见Stack overflow + Google)。 我敢肯定我没有。 还有其他原因吗?

我似乎已经查明了问题所在,我介绍了这个:

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

这似乎干扰了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:UserslaDocumentsVisual Studio 2010ProjectsBlaUpdater1Program.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) 您有同一类中的重复财产

(b) 如果您在绘图文件中向相关实体披露外国密钥,并使用 。如果是这种情况,则在外国密钥属性中添加 Indepte=“false”并更新=“false” ,然后再次运行。

校验此操作, 因为您正在使用流利和自动映射, 您需要查看 XML 映射 。 请查看此 [ link [ 2], 并使用 < code> ExportTo (.) 方法 。 一旦您查看了 < code> XML , 并查看是否有重复的属性或甚至重复映射文件 。

在您中,您可以两次引用列GI :

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

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

您无法在 < code> [DocumentId] 类属性上设置批注 < code> [DocumentId] 。 您可能需要放弃此类的自动映射, 并通过流利手动配置!

问题回答

@Rippo的功劳完全归功于@Rippo,

对于班级:

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

public class Department
{
   public virtual ICollection<User> Users {get; set;}
}

如果您拥有 user 实体的下列映射图:

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

以下是可能的解决办法之一(由于在 one-to-many part - one-unity-to-many-用户 中进行双重映射):

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

我有一个错误, 在我流利的 IAutomaping Override 类中, 我有一个映射。 Ignore Property (p {gt; p {gt; Property) 的属性只是一个获取器。 我删除了忽略映射的语句, 并修好了它。 这是与 NH 3. 3. 3. 3. 1. 4 有关的。 可能与您的问题无关, 但希望这对其他人有帮助 。





相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签