LINQ to SQL cannot read XML fields on SQL 2005?

Thursday, April 16 2009

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