Linq to sql Error "Data at the root level is invalid " for nullable xml column

Posted by Mukesh on Stack Overflow See other posts from Stack Overflow or by Mukesh
Published on 2010-02-26T12:49:48Z Indexed on 2010/03/20 23:51 UTC
Read the original article Hit count: 337

Filed under:
|
|
|
|

I have Created a table like

CREATE TABLE [dbo].[tab1]( 
 [Id] [int] NOT NULL, 
 [Name] [varchar](100) NOT NULL, 
 [Meta] [xml] NULL, 


CONSTRAINT [PK_tab1] PRIMARY KEY CLUSTERED  
( 
     [Id] ASC 
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

When I am doing linq to sql query to fetch a data it throw an error "data at the root level is invalid linq". In further investigation I come to know that the meta column is null in that case. In real it is nullable Do I have to remove the nullable and set some blank root node as default or there is some another way to get rid of the error.


My linq Query which throws error

     var obj1= (from obj in dbContext.tab1s
  where obj.id== 123
select obj).FirstOrDefault<Tab1>();

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about c#