相关疑难解决方法(0)

使用NHibernate接收索引超出范围

我希望有人可以帮我解决这个问题.我一直在绞尽脑汁,我的项目很快到期.先感谢您.

插入新记录时,我收到超出范围异常的索引.在无休止地搜索信息后,有人建议我的映射中的列值与我的持久化类中的列值不匹配.但是,我计算并重新计算,它们似乎匹配.正如您在下面的代码中所看到的,我正在使用NHibernate.Mapping.Attributes来进行映射.也许我在那里做错了什么.

我终于下载了NHibernate源代码并通过我的问题进行了调试.下面是NHibernate试图构建的insert语句:

{插入WTSLIB33T.PRODDATA(PSTAT,PCONO,PDVNO,PWKTY,PCRTY,PTSID,PCNNO,PDTTK,PJBNO,PSJNO,PTKNO,PCWNO,PWKAR,PWKDC,PWKCD,PCNWO,PWDNO,PDESC,PDCCD,PHRS,PUNIT,PSEQ ,PCUST)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )}

如您所见,参数数量与列表中的字段数相匹配.我还将这个生成的插入与我的类相匹配,我发现PSEQ和PCUST列与我的持久类无关.然后,在通过Dehydrate函数进行调试时,我发现了两个可能的问题.第一个是我注意到对NullSafeSet函数的调用将参数0设置为我的PSEQ字段应该设置为什么,但insert语句中的参数0是PSTAT.

我注意到的第二个问题是最后一次调用"index + = ArrayHelper.CountTrue(includeColumns [i]);" 在Dehydrate函数中,将索引变量保留为23,这是正确的; 但是,下一个调用"IdentifierType.NullSafeSet(statement,id,index,session);" ,它检查行id,传入索引23,这将超出范围.对于基于零的数组,该值应为22.


protected int Dehydrate(object id, object[] fields, object rowId, bool[] includeProperty, bool[][] includeColumns, int table, IDbCommand statement, ISessionImplementor session, int index)
            {
                    if (log.IsDebugEnabled)
                    {
log.Debug("Dehydrating entity: " + MessageHelper.InfoString(this, id, Factory));
                }
// there's a pretty strong coupling between the order of the SQL parameter
// construction and the actual order of the parameter collection.

for (int i = 0; i < entityMetamodel.PropertySpan; i++)
{ …
Run Code Online (Sandbox Code Playgroud)

nhibernate nhibernate-mapping

6
推荐指数
1
解决办法
6336
查看次数

从 IDataReader 读取字段时出现间歇性 System.IndexOutOfRangeException

我在代码中有一个非常奇怪的问题,我不希望它会失败。这是一个基于 AspDotNetStoreFront 的网站,有一些流量但不是那么大。尝试从读取器读取数据库字段时,站点间歇性崩溃。这发生在网站的不同地方。此类代码的示例在下面与object pValue = rs["PropertyValueString"]; 的行中。

private Dictionary<string, object> GetPropertValuePairs(string userName)
    {
        string query = string.Format("select PropertyName, PropertyValueString from dbo.profile with(nolock) where CustomerGUID = {0} and StoreID = {1}", DB.SQuote(userName),AppLogic.StoreID());

        Dictionary<string, object> propertyValues = new Dictionary<string, object>();

        using (SqlConnection conn = new SqlConnection(DB.GetDBConn()))
        {
            conn.Open();

            using (IDataReader rs = DB.GetRS(query, conn))
            {
                while (rs.Read())
                {
                    string pName = DB.RSField(rs, "PropertyName");
                    object pValue = rs["PropertyValueString"];

                    if (propertyValues.ContainsKey(pName) == false)
                    {
                        propertyValues.Add(pName, pValue);
                    }
                }

                rs.Close();
                rs.Dispose();
            }
            conn.Close();
            conn.Dispose(); …
Run Code Online (Sandbox Code Playgroud)

c# sql datareader sqlclient aspdotnetstorefront

5
推荐指数
1
解决办法
5199
查看次数

NHibernate - NHibernate.Exceptions.GenericADOException: 无法执行查询

我有以下看似随机发生的异常:

    NHibernate.Exceptions.GenericADOException: could not execute query
    [ select businesspr0_.BusinessProcessID as col_0_0_, businesspr0_.ProcessNumber as col_1_0_, businesspr1_.Name as col_2_0_, businesspr0_.DateCreated as col_3_0_, actor2_.DisplayName as col_4_0_, usergroup3_.Name as col_5_0_, processele5_.Name as col_6_0_ from BusinessProcess businesspr0_ inner join BusinessProcess businesspr1_ on businesspr0_.DefinitionID=businesspr1_.BusinessProcessID inner join Actor actor2_ on businesspr0_.ActorCreatedID=actor2_.ActorID left outer join UserGroup usergroup3_ on businesspr0_.UserGroupCreatedID=usergroup3_.UserGroupID left outer join Actor usergroup3_1_ on usergroup3_.UserGroupID=usergroup3_1_.ActorID inner join ActiveElement activeelem4_ on businesspr0_.BusinessProcessID=activeelem4_.BusinessProcessID inner join ProcessElement processele5_ on activeelem4_.ProcessElementID=processele5_.ProcessElementID inner join ProcessEmployees processemp6_ on businesspr0_.BusinessProcessID=processemp6_.BusinessProcessID inner join Actor actor7_ …
Run Code Online (Sandbox Code Playgroud)

c# nhibernate

5
推荐指数
1
解决办法
1万
查看次数

Nhibernate FieldNameLookup抛出IndexOutOfRangeException

我们偶尔会遇到这个非常奇怪的错误

NHibernate.ADOException: could not execute query
[ SELECT this_.Id as Id37_0_, this_.AREA_ID as AREA2_37_0_, this_.BAT_CHK as BAT3_37_0_, this_.BAT_COD as BAT4_37_0_, this_.BBEACT as BBEACT37_0_, this_.CREDATE as CREDATE37_0_, this_.DEST_LOC as DEST7_37_0_, this_.DOCNR as DOCNR37_0_, this_.DOCTYPE as DOCTYPE37_0_, this_.DUTY_STATUS as DUTY10_37_0_, this_.EAN as EAN37_0_, this_.EXCEPTION_REASON as EXCEPTION12_37_0_, this_.ERROR_TEXT as ERROR13_37_0_, this_.FLOWTYPE as FLOWTYPE37_0_, this_.GOODS_STATUS as GOODS15_37_0_, this_.INSERT_DATETIME as INSERT16_37_0_, this_.MATNR as MATNR37_0_, this_.MVTTYPE as MVTTYPE37_0_, this_.ORDNR as ORDNR37_0_, this_.PACK_ID as PACK20_37_0_, this_.PALNR as PALNR37_0_, this_.PRDACT as PRDACT37_0_, this_.QTYLOAD as QTYLOAD37_0_, this_.SCANNR as SCANNR37_0_, …
Run Code Online (Sandbox Code Playgroud)

nhibernate ado.net

2
推荐指数
1
解决办法
2309
查看次数