Error deleting record using Linq2SQL

I recently received an error message from a client and I was not able to resolve it. I hope someone can give me some idea of ​​what might be wrong.

The error seems simple enough:

Csla.DataPortalException: DataPortal.Delete failed (System.InvalidOperationException: The sequence contains more than one element in System.Linq.Enumerable.SingleOrDefault [TSource] (source IEnumerable`1)

Here is my DataPortal_Delete method, which takes a FileId (PK) parameter as a parameter.

private void DataPortal_Delete(SingleCriteria<File, Guid> criteria) { using (var ctx = ContextManager<Ronin.Data.RoninDataContext> .GetManager(Database.ApplicationConnection, false)) { var data = ctx.DataContext.Files .Single(row => row.FileId == criteria.Value); ctx.DataContext.FileSources.DeleteAllOnSubmit(data.FileSources); ctx.DataContext.Files.DeleteOnSubmit(data); ctx.DataContext.SubmitChanges(); } } 

The first thing I checked was to check if there was another entry with the same FileId (although it was a primary key, this should be impossible). All FileIds were truly unique. I launched the application connecting to the client database and tried to delete the entry and it worked without any problems. An IT guy on a client site used the Problem Step Recorder to send me step-by-step screenshots of the actions taken by the user. Nothing unusual, and when he used another machine, he was able to delete the record without any errors. Apparently, this only happens when the application starts in Windows 7.

However, any ideas as to what might be causing this?

+6
linq-to-sql csla
source share
3 answers

Assuming the Single call is the source of the problem, not:

 ctx.DataContext.Files.Single(...) 

modify the code so that you can return multiple rows from this query and then register what it returns when it returns more than one row. This should indicate your problem with "duplicate" data.

Another thing worth paying attention to is SQL, which is created behind the scenes. Not sure if this will help, but it will not hurt. I do not know your data model, so I can not understand your code, and would also like to.

+1
source share

If this only happens on Windows 7, it could be the cause of the OS. Have you tried this on Vista? Vista is similar to Windows 7. You can also use Windows Virtual PC + XP Mode. This is a virtualization application specifically designed for Windows 7 that allows users to run applications as they are used in Windows XP. Note. XP mode requires a processor with virtualization support.

0
source share

I had the same exception when deleting an object one . The problem turned out to be the external link defined in the dbml File. Thus, this caused an exception in my case. After I deleted this, he deleted the record (and I didn’t want to cascade delete records from another table, I just need to figure out how to configure linq-to-sql to just set the foreign key column to null)

0
source share

All Articles