LINQ delete error (C#)
/// <summary>
/// Deletes all data record开发者_JAVA技巧s associated with a data record ID
/// </summary>
/// <param name="DataID">Data ID record</param>
public static void DeleteDataLabels(int DataId)
{
using (var dc = new ArtworkingDataContext())
{
// Delete associated datalabels
var q = dc.tblArtworkDataLabels.Where(c => c.dataID == DataId);
if (q.Count() != 0)
{
dc.tblArtworkDataLabels.DeleteAllOnSubmit(q);
dc.SubmitChanges();
}
}
}
If there are records to delete in the DB, it throws:
Exception Details: System.Data.SqlClient.SqlException: The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
On
dc.SubmitChanges();
Bit confused about this one!
Try setting UpdateCheck
to Never
in ColumnAttribute
s of offending columns:
[Column(..., UpdateCheck = UpdateCheck.Never)]
I now this may sound absurd, but I had exactly same problem recently and my research suggested that I delete the table in my dbml and drag it in again and guess what, its fixed! So try deleting your tblArtworkDataLabels and recreate it.
I dont know whether it was my changes that caused the out of synch between the model and my db, or it was purely VS issue.
Perhaps your DBML file is no longer up to date?
Apart from that, you should profile the SQL that is being sent to the database, in that way you can see what is really happening.
精彩评论