2
/// <summary>
/// Deletes all data records 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!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
  • Can you change and UPDATE one of those? Sounds like an error in your binding attributes. – H H Mar 24 '11 at 13:00
  • Is your dataId column a text / ntext column? – Tejs Mar 24 '11 at 13:02
  • This looks similar to your issue: [linq-problems-with-ntext-text-and-image-on-sql-server](http://stackoverflow.com/questions/1460251/linq-problems-with-ntext-text-and-image-on-sql-server) – firefox1986 Mar 24 '11 at 13:02

3 Answers3

3

Try setting UpdateCheck to Never in ColumnAttributes of offending columns:

[Column(..., UpdateCheck = UpdateCheck.Never)]
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
2

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.

Fadrian Sudaman
  • 6,405
  • 21
  • 29
  • Thanks, this worked! Weird. It's annoying because I know have to re-add all my associations into the diagram though – Tom Gullen Mar 24 '11 at 13:05
2

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.

Pleun
  • 8,856
  • 2
  • 30
  • 50