Jeff-Lewis / codesmith

Automatically exported from code.google.com/p/codesmith
0 stars 0 forks source link

Unable using Delete for Many to Many list of entity #110

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When we try to use

context.item.Delete(item.ManyToManyList.AsQueryable());

we get the following error:

System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
   at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32
length, Boolean fAlwaysCopy)
   at System.Data.Linq.TableExtensions.GetBatchJoinQuery[TEntity](Table`1
table, IQueryable`1 entities)
   at
System.Data.Linq.TableExtensions.GetDeleteBatchCommand[TEntity](Table`1
table, IQueryable`1 entities)
   at System.Data.Linq.TableExtensions.Delete[TEntity](Table`1 table,
IQueryable`1 entities)

Any ideas?

Original issue reported on code.google.com by kachalkov on 24 Jun 2009 at 3:01

GoogleCodeExporter commented 9 years ago
The delete you are executing is looking for a LINQ to SQL query.  To delete 
multiple 
objects in this manner, you should use context.item.DeleteAllOnSubmit.

context.item.DeleteAllOnSubmit(item.ManyToManyList);
context.SubmitChanges();

Original comment by shannon....@gmail.com on 29 Jun 2009 at 9:04