LINQ to Entities 不支持 LINQ 表达式节点类型“ArrayIndex”

本文介绍了一个关于 LINQ to Entities 在使用 ArrayIndex 时出现的 NotSupportedException 异常,并详细展示了错误堆栈跟踪信息,有助于开发者理解问题所在并找到相应的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我就不屁话,能一张图就解决的就不说话了

 

2015-03-28 14:53:24,440 [10] ERROR log - System.NotSupportedException: LINQ to Entities 不支持 LINQ 表达式节点类型“ArrayIndex”。
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.NotSupportedTranslator.Translate(ExpressionConverter parent, Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.EqualsTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.BinaryTranslator.TypedTranslate(ExpressionConverter parent, BinaryExpression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
在 System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
在 System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__2()
在 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
在 System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__1()
在 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
在 System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
在 System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
在 System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
在 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
在 LoTBlog.Back.Controllers.ArticleController.Update(Int32 GroupType, Int32 ArticleId) 位置 c:\Users\DNT\Desktop\LoTCode\LoTBlog\LoTBlog.Back\Controllers\ArticleController.cs:行号 272
在 lambda_method(Closure , ControllerBase , Object[] )
在 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
在 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeSynchronousActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
在 System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
在 System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
在 System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult)
在 System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
在 System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20()
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)

转载于:https://www.cnblogs.com/dunitian/p/4374273.html

using Com.Huancare.Medical.Lis.Communication.ProtocolBase.Serial; using NetworkClient.Entities; using System; using System.Collections.Generic; using System.Data; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading; using System.Timers; namespace Com.Huancare.Medical.Lis.Communication.Protocol.Serial { /// <summary> /// 曾口中心卫生院 /// 尿检机 曼特诺matenu US200 /// </summary> public class SerialUS200Svr : SerialSvrReceiveData { byte[] btBuffer = new byte[1024]; int iCurrentIndex = 0; private string strHosEquipID; private string strHosID; private string strPortName; private DataTable dtChannelAndValue = null; StringBuilder sbCache = new StringBuilder(); /// <summary> /// 记时器 /// </summary> System.Timers.Timer timer = new System.Timers.Timer(300); // 0.3s public SerialUS200Svr(string strPortName, int iBaudRate, int iDataBits, StopBits stopBits, Parity parity, int iBufferSize, string strShakeHands, string strReply, string strEndShakeHands, string strEndReply) : base(strPortName, iBaudRate, iDataBits, stopBits, parity, iBufferSize, strShakeHands, strReply, strEndShakeHands, strEndReply) { this.strPortName = strPortName; timer.Elapsed += new System.Timers.ElapsedEventHandler(SaveData); timer.AutoReset = false; InitChannelAndValue(); } private void InitChannelAndValue() { dtChannelAndValue = new DataTable(); dtChannelAndValue.Columns.Add("PaperType", typeof(string)); dtChannelAndValue.Columns.Add("ChannelName", typeof(string)); dtChannelAndValue.Columns.Add("RowIndex", typeof(int)); dtChannelAndValue.Columns.Add("ValueIndex", typeof(int)); dtChannelAndValue.Columns.Add("Value", typeof(string)); int iValueIndex = 0; int iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "3+"); iValueIndex = 1; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "BIL", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "BIL", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "BIL", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "BIL", iValueIndex, iRowIndex++, "3+"); iValueIndex = 2; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "3+"); iValueIndex = 3; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "3+"); iValueIndex = 4; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "3+"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "3+"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "4+"); iValueIndex = 5; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "NIT", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "NIT", iValueIndex, iRowIndex++, "+"); iValueIndex = 6; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "3+"); iValueIndex = 7; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "3+"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "4+"); iValueIndex = 8; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.030"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.025"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.020"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.015"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.010"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.005"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.000"); iValueIndex = 9; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "4.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "5.0"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "5.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "6.0"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "6.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "7.0"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "7.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "8.0"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "8.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "9.0"); iValueIndex = 10; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "6.0"); dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "3.0"); dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "1.4"); dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "0.6"); dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "0"); } protected override void PacketReceived(byte[] btRecData, string strHosEquipID, string strHosID) { try { this.strHosEquipID = strHosEquipID; this.strHosID = strHosID; if (btRecData[0] == 0x41) iCurrentIndex = 0;//开始标志 Array.Copy(btRecData, 0, btBuffer, iCurrentIndex, btRecData.Length); iCurrentIndex += btRecData.Length; if (btRecData[btRecData.Length - 1] == 0x42)//结束标志 { iCurrentIndex = 0; } timer.Enabled = false; this.strHosEquipID = strHosEquipID; this.strHosID = strHosID; sbCache.Append(Encoding.ASCII.GetString(btRecData)); timer.Enabled = true; } catch (Exception) { } } private void SaveData(object sender, System.Timers.ElapsedEventArgs e) { string strRecData = ""; lock (this) { strRecData = sbCache.ToString(); sbCache.Remove(0, sbCache.Length); } ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProcessReceiveData), strRecData); } private void ThreadProcessReceiveData(object objRecString) { string strPackets = objRecString.ToString(); try { //string strRecData = ExtractLowest(strPackets.Replace(" ", "")); string strRecData = strPackets.Replace(" ", ""); string strSave = ""; strSave += strRecData.Substring(1, 6);//上机号 strSave += "|"; //报文中没有年份和秒 strSave += DateTime.Now.Year.ToString().Substring(0, 2) + strRecData.Substring(7, 10) + "01";//上机时间 strSave += "|"; //00 URS-8 传送数据的倒数第二位至第五位为随机数无效 //01 URS-10 传送数据的倒数第二位至第三位为随机数无效 //02 F11-2 传送数据的倒数第二位无效 //03 URS-11 传送数据与试纸使用顺序相同 string strPaperType = strRecData.Substring(17, 2);//试纸类型 //00 旧制(E) //01 旧制(+-) //02 SI制(E) //03 SI制(+-) string strUnitType = strRecData.Substring(19, 2);//单位 string strValues = strRecData.Substring(21, 12);//结果 int iIndex = 0; for (int i = 0; i < strValues.Length; i++) { string strVal = strValues.Substring(i, 1); DataRow dtRow = this.GetUS200TableValue(strPaperType, iIndex++, strVal); if (dtRow != null) { string strChannelName = dtRow["ChannelName"].ToString();//通道号 string strChannelValue = dtRow["Value"].ToString();//通道号 strSave += strChannelName; strSave += ":"; strSave += strChannelValue; strSave += ";"; } } strSave += "|"; //btRecData = System.Text.Encoding.Default.GetBytes(strSave); string strOptMsg = SaveReceiveData.SaveReceivePacked(this.strHosID, this.strHosEquipID, strSave); base.OnReceiveDatas(this.strHosEquipID, strPortName, new ReceiveDatasEventArgs(Encoding.UTF8.GetBytes(strSave), strOptMsg)); } catch (Exception ex) { base.OnReceiveDatas(this.strHosEquipID, strPortName, new ReceiveDatasEventArgs(Encoding.UTF8.GetBytes(strPackets), ex.Message)); } } /// <summary> /// 根据试纸类型 顺序 值索引 查询对应的结果值 /// </summary> /// <param name="strPaperType">试纸类型</param> /// <param name="iIndex">顺序 即行号</param> /// <param name="strValIndex">值索引</param> /// <returns></returns> private DataRow GetUS200TableValue(string strPaperType, int iIndex, string strValIndex) { DataRow dtRowRet = null; try { if (dtChannelAndValue == null) this.InitChannelAndValue(); dtRowRet = dtChannelAndValue.Select("PaperType = '" + strPaperType + "' And RowIndex = " + iIndex + " And ValueIndex = '" + strValIndex + "'")[0]; } catch (Exception) { } return dtRowRet; } //static string ExtractLowest(string hexString) //{ // //string result = ""; // //for (int i = 0; i < hexString.Length; i += 2) // //{ // // string pair = hexString.Substring(i, 2); // // int value = Convert.ToInt32(pair, 16); // // result += Convert.ToString(value % 10, 16); // 取最低值 // //} // //return result; //} } }
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值