3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

That's my namespaces. I was looking for System.Data.Linq; but it doesn't seem to be anywhere, and I guess that is what have been moved to System.Linq, since I have access to most other things in Linq. I've found System.Data:Linq, but no difference.

Here is my method:

public void deleteStudienummer(int studienummer)
{
    dbcontent = new DBEntities();

    var dQry = from members in dbcontent.Medlemmer
               where members.Studienummer == studienummer
               select members;

    foreach (var member in dQry)
    {
        dbcontent.***
    }
    dbcontent.AcceptAllChanges();
    Console.WriteLine("delete member should have occured");
}

The *** was supposed to be DeleteOnSubmit, but I only have DeleteDatabase and DeleteObject, I tried the latter but it doesn't work.

Have also tried dbcontent.Medlemmer.* but still not present.

And AcceptAllChanges() was supposed to be .submitChanges() but that wasn't present either.

1
  • I believe your namespace using statement only needs to be System.Linq. But you need to make sure you reference the System.Data.Linq assembly at the project level. Jan 10, 2011 at 19:40

5 Answers 5

4

As far as I know DeleteOnSubmit can only be called from a 'Table' not from a DataContext. Looks like you're trying to call DeleteOnSubmit from the context.

Should be dbcontent.Medlemmer.DeleteOnSubmit(member);

When using Linq to Entities as in this case dbContent.DeleteObject(member) can be used to mark for deletion. After that dbContent.SaveChanges() needs to be called to apply the changes. (AcceptAllChanges() won't do the deletion).

5
  • Not present there either. :-( Jan 10, 2011 at 19:40
  • Are you using Linq to Entities ? So could dbContent.DeleteObject(member); do the trick? Jan 10, 2011 at 20:08
  • Yeah Linq to Entities, sry if it wasnt clear. tried doing that, doesnt delete anything Jan 10, 2011 at 20:14
  • I'm not really a Linq2Entities person - so I read the doc: I guess AcceptAllChanges() won't do the deletion. In my understanding dbContent.SaveChanges() should be the method to persist the changes. Jan 10, 2011 at 20:28
  • yeah it just gives an error, but i just read that aswell :-) Else thanks. if u just edit it up there ill submit it as answer Jan 11, 2011 at 12:02
1

You don't call DeleteOnSubmit on your DataContext - you call it on an ITable or a Table<TEntity>. For example:

dbcontent.Medlemmer.DeleteOnSubmit(member);

DataContext.SubmitChanges should be present though...

The namespaces haven't changed, so I'm not sure why System.Data.Linq isn't showing up for you. Do you have a reference to the System.Data.Linq.dll? I'm surprised your code is building at all if you don't have that reference, as that should be required for your DBEntities class.

2
  • Not present there either. :-( Jan 10, 2011 at 19:39
  • @Anders: See my final paragraph - you need a reference to System.Data.Linq.
    – Jon Skeet
    Jan 10, 2011 at 19:40
1

You need to add a reference to System.Data.Linq Picture

2
  • @Anders: Is DBEntities in the same project, or a different one?
    – Jon Skeet
    Jan 10, 2011 at 19:41
  • It is in under Properties - Datasources.. Is that good enough? :) Jan 10, 2011 at 19:47
1

You could try the following:

   foreach (var member in dQry)
    {
        dbcontent.Medlemmer.DeleteOnSubmit(member);
    }
1

I was having this problem as well and had to add the reference to System.Data.Linq.

However as well as adding the reference to System.Data.Linq, also remove the following using statments:

//using System.Linq;
//using System.Linq.Expressions;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.