這個確切的標題可以在谷歌或這裏在stackflow.com多次發現,但我得到這個錯誤的原因是像他們都沒有:我在單位沒有問題測試代碼,但應用程序中完全相同的代碼會導致此問題。我希望這是因爲製圖問題。這個SqlParameterCollection的計數= 13的索引13無效
這裏是我的映射:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="My.Domain" namespace="My.Domain">
<class name="My.Domain.ReportFormFlag, My.Domain" table="ReportFormFlag" schema="Core">
<id name="FlagID">
<column name="FlagID" sql-type="uniqueidentifier" not-null="true"/>
<generator class="guid"/>
</id>
<property name="ReportInstanceID" column="ReportInstanceID" type="int" not-null="true"/>
<property name="FormID" column="FormID" type="int" not-null="true"/>
<property name="SiteOrProjectID" column="SiteOrProjectID" type="int" not-null="true"/>
<property name="IsFlagged" column="IsFlagged" type="int" not-null="true"/>
<property name="FlagComment" column="FlagComment" type="string" not-null="false"/>
</class>
</hibernate-mapping>
and here is my class
namespace My.Domain
{
[Serializable]
public class ReportFormFlag
{
public virtual Guid FlagID { get; set; }
public virtual int ReportInstanceID { get; set; }
public virtual int FormID { get; set; }
public virtual int SiteOrProjectID { get; set; }
public virtual int IsFlagged { get; set; }
public virtual string FlagComment { get; set; }
}
}
我用它來插入新記錄代碼:
var reportFormFlag = new ReportFormFlag
{
ReportInstanceID = 3554,
FormID = 25,
SiteOrProjectID = 0,
FlagComment = "test",
IsFlagged = 1
};
_provider.Save(reportFormFlag);
在NUnit的測試工作正常,但在應用程序中保存()引起的「Count = N的SqlParameterCollection的索引N無效」異常。
我使用的是NH 3.0,C#3.5,SQL Server 2008 R2。
任何洞察力非常感謝!
你說它在單元測試中運行良好...是否與同一個數據庫相反?使用相同的_provider? – Goblin 2012-07-22 19:57:54