Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a NVarChar(MAX) column with Linq causing an error

Tags:

c#

linq

I am trying to make an update on an existing value in my database using Linq in C#.

I instantiate the variable:

var projectTrackingEntity = context.project_trackings.Single(pt => pt.project_id == projectId);

Then I update the action column(it is a NVarChar(MAX)), but I am checking if it already has an action. If so I just add on to it with a semi-colon eg. action1;action2

When I call:

context.SubmitChanges();

I get this error while debugging:

System.NotSupportedException: SQL Server does not handle comparison of NText, Text, Xml, or Image data types.

I have tried setting UpdateCheck = UpdateCheck.Never, but that doesn't fix the problem.

EDIT: Adding the code where I update the actions (the variable "action" is a string)

var actions = projectTrackingEntity.action.Split(';');
bool equalActions = false;
foreach (string a in actions)
{
    if (string.Equals(a, action, StringComparison.CurrentCultureIgnoreCase))
    {
        equalActions = true;
        break;
    }
}
if(!equalActions)
{
    projectTrackingEntity.action = string.IsNullOrEmpty(projectTrackingEntity.action) ? //if
        action : //true
        projectTrackingEntity.action + ';' + action; //false
}

context.SubmitChanges();
like image 207
Adam Calvert-Piotrowicz Avatar asked Dec 06 '25 08:12

Adam Calvert-Piotrowicz


1 Answers

Method 1:

For fix this issue just open the dbml file with xml editor and set the updatecheck to Never as follows:

<column canbenull="true" dbtype="Xml" name="PermissionsXml" type="System.Xml.Linq.XElement" updatecheck="Never"></column>  

Method 2:

Change your field in to a VARCHAR(max)

Method 3:

change UpdateCheck to UpdateCheck.WhenChanged

I hope this will help to you.

like image 113
Sampath Avatar answered Dec 07 '25 22:12

Sampath