c# - "InnerText" on XmlNode in LINQ query do not work -


When I call a property "intrite" on the XMLNode in the LINQ query, I get a strange error: "One object Key has already been added. "

looks like the query:

  var partnersXml = in dataContext.SomeTableInDb the partnerTable where partnerTable.XmlType ==" partner " Select new {PARTNERID = XmlDocumentWrapper (partnerTable.XmlDocument). SelectionSingleNode ("// * [name () = 'partnerId']"). Entertext};  

Explanation:

  • partnerTable.XmlDocument string XML DB
  • XmlDocumentWrapper method gives an XmlDocument for an XML string

The query works perfectly without "intrtext" (then there is XmlNode in partnerId). Is there some kind of bug in LINQ or what? What is the solution to this problem?

Stack trace:

System.ArgumentException: An object with the same key has already been added. System.ThrowHelper.ThrowArgumentException on System.Data.Linq.Mapping.UnmappedType.GetDataMember (ExceptionResource Resources) System.Collections.Generic.Dictionary 2.Insert (on TKey key, TValue value, Boolean add) (MemberInfo miles) System.Data.Linq.SqlClient.SqlFactory.Member (SqlExpression expr, MemberInfo members System.Data.Linq.SqlClient.QueryConverter.VisitInner) on System.Data.Linq.SqlClient.QueryConverter.VisitMemberAccess (MemberExpression mA) (expression node ) on System.Data.Linq.SqlClient.QueryConverter.Visit (expression node System.Data.Linq.SqlClient.QueryConverter.VisitNew) on System.Data.Linq.SqlClient.QueryConverter.VisitExpression (expression Exp) (NewExpression Qn) System.Data.Linq.SqlClient.QueryConverter.VisitInner (Expression Node) System.Data.Linq. On System.Data.Linq.SqlClient.QueryConverter.VisitSelect on SqlClientkQueryConverterkVisit (expression node) (expression sequence, LambdaExpression selector) on the system. SystemCode.Linq.SqlClient.QueryConverter.VisitMethodCall (MethodCallExpression MC) on YConverter.VisitSequenceOperatorCall (MethodCallExpression mc) on System.Data.Linq.SqlClient.QueryConverter at Data.Linq.SqlClient.Quer System.Data.Linq.SqlClient.QueryConverter.VisitInner . ConvertOuter (Expression Node) on System.Data.Linq.SqlClient.SqlProvider.BuildQuery (Expression Query, SqlNodeAnnotations Annotation) on System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute (Expression Query) 1.System.Collections.Generic.IEnumerable.GetEnumerator (on System.Data.Linq.DataQuery)

It seems that LINQ is trying to mimic SQL, while you want to do it in the .NET side. (I think - if you want to database XPath, then I do not know that I'm scared.) Try this:

  var partnersXml = dataContext.SomeTableInDb Where (x = & gt; X.XmlType == "partner"). ANNMerebel () // This forces the rest of the questions to be done in CLR. Select (x = & gt; new {partnerId = XmlDocumentWrapper (x.XmlDocument). SelectSingleNode ("/ / * [name () = 'partner id']") .intertext});  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -