C# 3.0 in a Nutshell
C# 3.0 in a Nutshell, Third Edition A Desktop Quick Reference By Joseph Albahari, Ben Albahari
September 2007
Pages: 858


Welcome Guest ( Log In | Register )

How To Delete An Entity Before Submitchanges ?
Bassam EG
post May 28 2009, 04:28 AM
Post #1


New Member
*

Group: Members
Posts: 4
Joined: 28-April 09
Member No.: 17,843



Hello, I have this simple code using LINQ to SQL :

Customer c = New Customer { Name = "C1", Age = 22 };
Customer c1 = New Customer { Name = "C2", Age = 20 };

ctx.Customers.InsertOnSubmit( c )
ctx.Customers.InsertOnSubmit(c1)

\\now the 2 new entities are in the datacontext , i want to remove the second customer - for whatever reason like if a user discovered that he entered it by error -

I want to do that before i submit changes

DeleteOnSubmit will give an exception because those 2 entities are not tracked by the datacontext yet because they are new, their status is UnTracked

this sound very simple but i can't find a answer for it !!

Thank you
Bassam

This post has been edited by Bassam EG: May 28 2009, 04:30 AM
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 22nd November 2009 - 04:14 PM