Linq to sql "Root level data invalid" error for xml null column

I 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 do linq for a sql query to retrieve data, it throws an error "data at the root level is invalid linq". In further research, I find out that the meta column in this case is null. In reality, this value is null. Should I remove the nullable value and set the empty node to empty by default or is there another way to get rid of the error.


My Linq query that causes an error

     var obj1= (from obj in dbContext.tab1s
  where obj.id== 123
select obj).FirstOrDefault<Tab1>();
+3
source share
2 answers

, XML NULL.

, XML, .

SQL Server :

UPDATE tab1
SET Meta = 'blah'
WHERE id = 123

, "blah" XML, SQL Server . Linq to SQL , XML XElement. , โ€‹โ€‹ , .

, XML, .

+2

[tab1], [tab1s]

0

Source: https://habr.com/ru/post/1734547/


All Articles