473,626 Members | 3,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete Record with LINQ

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
3 24217
just create the var of your record u need to delete
like var myItemToDel = GetRecordToDele te();
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
On Dec 4, 3:42 am, Michael Nemtsev <nemt...@msn.co mwrote:
just create the var of your record u need to delete
like var myItemToDel = GetRecordToDele te();
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 UndefinedDataCo ntext
Dim tag As Tag = From t In database.Tags _
Where t.TagID = New Guid("5f8f46cc-709c-
dc11-8760-000e35bd65c3")
database.Tags.R emove(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
Well, trying something similar on Northwind and using the RTM tools:

Customer cust = ctx.Customers.W here(c =c.CustomerID
== "ALFKI").Single ();
ctx.Customers.D eleteOnSubmit(c ust);
ctx.SubmitChang es();

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3963
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to delete a record in this subform. When I switched modal off and tried to delete a record from the list, I deleted a record on another form (below the popup form).
4
2569
by: Craggy | last post by:
Hi, I am trying to pop up a yes/no message box so that a user can delete a record in a continuous form. The default delete message is a bit sloppy because it seems to move the continuous form to the position of the record u want to delete. If you then choose to not to delete the record it looks to a user as if it has deleted every record before the one you chose not to delete. To get around this I made a yes/no msgbox pop up and only after...
2
5476
by: shapper | last post by:
Hello, I have two tables: TagId, PostId TagId, PostId How can I delete, given a TagId, the record from Tags and all records associated with it in PostTags.
3
3522
by: Phil Stanton | last post by:
I have a form based on a complex query (Lots of tables) If I delete a record, everything appears to be OK. Get the message "Youa are about to delete 1 record ....". I say yes. The record count goes down correctly. Then if I do Records-->Remove Filter/Sort there are the deleted records back as if they had never been deleted. Same thin exactly if I do the operation on the form's recordsource query, so that eliminates anything to do with...
0
1078
by: shapper | last post by:
Hello, I have a ListView as defined as follow: Private Sub lv_ItemDeleting(ByVal sender As Object, ByVal e As ListViewDeleteEventArgs) Handles lv.ItemDeleting Dim database As New TestDataContext Dim tag As Tag = From t In database.Tags _ Where t.TagID = lv.DataKeys(e.ItemIndex).Value
2
1467
by: shapper | last post by:
Hello, I have a ListView defined as follows: Private Sub lv_Init(ByVal sender As Object, ByVal e As EventArgs) Handles lv.Init lv.DataKeyNames = New String() {"TagID"} lv.ID = "lv" lvTags.ItemTemplate = New MyItemTemplate() lvTags.LayoutTemplate = New MyLayoutTemplate()
4
4397
by: barkarlo | last post by:
I use check box in a form "frmworkorder" like confirmation that's record finish. How can I write code who will block edit and delete record in form when is check box confirmed.
3
2175
by: shapper | last post by:
Hello, I have 3 tables, Tags, ArticlesTags and FilesTags, with the following columns: Tags TagID, Text ArticlesTags TagID, ArticleID FilesTags TagID, FileID
1
1614
by: CreativeMind | last post by:
hi all, private void dgMygrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { Button bDelete=(Button)e.Item.FindControl("btnDelete"); if(bDelete!=null) { bDelete.Attributes.Add("OnClick","javascript:return confirm('Are you sure you want to delete this sales person?');");
0
8262
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8701
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6122
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1507
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.