LINQ to SQL cannot read XML fields on SQL 2005?

This is a limitation I found using LINQ to SQL creating a class. I use a table that had a field as an XML element and I received this error below.

DBML1005: Mapping between DbType 'Xml' and Type 'System.Xml.Linq.XElement' in Column

I found only this information on the web about this problem a bug that Microsoft already close and no new comments can be added.

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361451

I make sure I have VS2008 and Service Pack 1 install, so this error should not happen to me.

How did I resolve the issue? Well there are 2 ways, change the type of the field on the database, I know that is almost never possible, or go to the properties of that field inside the LINQ to SQL class, change the type from XmlDocument to XElement.

Hope this helps

Cheers

Al

Follow me in twitter | bookmark me | Subscribe to my feed

Published Thursday, April 16, 2009 10:06 PM by albertpascual
Filed under: ,

Comments

# re: LINQ to SQL cannot read XML fields on SQL 2005?

Friday, April 17, 2009 3:22 PM by rajbk

I am able to compile without any issues in VS team system 2008 for Developers. The type was already set to "XElement (System.Xml.Linq.XElement)"

V 9.0.30729.1 SP

Raj

# re: LINQ to SQL cannot read XML fields on SQL 2005?

Thursday, May 07, 2009 6:30 AM by Sven

My solution for this:

1. Open dbml designer.

2. Select the xml column of the table.

3. in the properties window, delete the "XML" or "XML NOT NULL" value of the property "Server Data Type" (just let it empty).

4. The solution now compiles and runs without any problem.

This MS connect issue indeed has been closed, but you're still able to add comments/suggestions.

Leave a Comment

(required) 
(required) 
(optional)
(required)