When I call a property "InnerText" on XmlNode in LINQ query I am getting a strange error: "An item with the same key has already been added.".
Query looks like:
var partnersXml = from partnerTable in dataContext.SomeTableInDb
where partnerTable.XmlType == "partner"
select new
{
partnerId = XmlDocumentWrapper(partnerTable.XmlDocument).SelectSingleNode("//*[name()='partnerId']").InnerText
};
Explanation:
- partnerTable.XmlDocument is string xml in DB
- XmlDocumentWrapper method returns a XmlDocument for a given xml string
Query works perfectly without "InnerText" (then partnerId contains XmlNode). Is this some kind of bug in LINQ or what? What is a workaround of this problem?
Stack trace:
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)
at System.Data.Linq.Mapping.UnmappedType.GetDataMember(MemberInfo mi)
at System.Data.Linq.SqlClient.SqlFactory.Member(SqlExpression expr, MemberInfo member)
at System.Data.Linq.SqlClient.QueryConverter.VisitMemberAccess(MemberExpression ma)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitNew(NewExpression qn)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.Visit(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitSelect(Expression sequence, LambdaExpression selector)
at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node)
at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery
1.System.Collections.Generic.IEnumerable.GetEnumerator()