By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,811 Members | 785 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,811 IT Pros & Developers. It's quick & easy.

Delete Record with LINQ

P: n/a
Hello,

I have a table named Tags with the following columns: TagId and
TagValue.
How can I delete a record, using LINQ, given the TagId value.

Thanks,
Miguel
Dec 3 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
just create the var of your record u need to delete
like var myItemToDel = GetRecordToDelete();
and then use .DeleteOnSubmit(myItemToDel)
--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog: http://spaces.live.com/laflour

"shapper" wrote:
Hello,

I have a table named Tags with the following columns: TagId and
TagValue.
How can I delete a record, using LINQ, given the TagId value.

Thanks,
Miguel
Dec 4 '07 #2

P: n/a
On Dec 4, 3:42 am, Michael Nemtsev <nemt...@msn.comwrote:
just create the var of your record u need to delete
like var myItemToDel = GetRecordToDelete();
and then use .DeleteOnSubmit(myItemToDel)
--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog:http://spaces.live.com/laflour

"shapper" wrote:
Hello,
I have a table named Tags with the following columns: TagId and
TagValue.
How can I delete a record, using LINQ, given the TagId value.
Thanks,
Miguel
Hi,

I am using the following:

Dim database As New UndefinedDataContext
Dim tag As Tag = From t In database.Tags _
Where t.TagID = New Guid("5f8f46cc-709c-
dc11-8760-000e35bd65c3")
database.Tags.Remove(Tag)

But this is not working. I am using a fixed Guid just for testing.
I am using VB.NET but I understand C# so any suggestion can be in C#.

Thanks,
Miguel
Dec 4 '07 #3

P: n/a
Well, trying something similar on Northwind and using the RTM tools:

Customer cust = ctx.Customers.Where(c =c.CustomerID
== "ALFKI").Single();
ctx.Customers.DeleteOnSubmit(cust);
ctx.SubmitChanges();

Does this not work? Does it error? or do nothing?

Note - the query is equivalent to below - but in this example I find
the Where(...) etc clearer...

Customer cust = (from c in ctx.Customers // your
objects
where c.CustomerID == "ALFKI" // your
guid etc
select c).Single();

Marc
Dec 4 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.