Reputation: 6237
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.
Upvotes: 3
Views: 8913
Reputation: 11
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;
Upvotes: 1
Reputation: 193
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).
Upvotes: 4
Reputation: 51
You could try the following:
foreach (var member in dQry)
{
dbcontent.Medlemmer.DeleteOnSubmit(member);
}
Upvotes: 1
Reputation: 1501646
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.
Upvotes: 1