LinQ to SQL - InsertOnSubmit without SubmitChanges
up vote
0
down vote
favorite
Suppose that I inserted an entity to an entity set by calling the InsertOnSubmit method , like this :
DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
// db.SubmitChanges();
I didnt call SubmitChanges intentionally .
My question is , can i later find that product and delete it with DeleteOnSubmit method?:
Product product = db.Products.Single(p => p.ID == "1");
db.Products.DeleteOnSubmit(product);
If i cannot , then what the InsertOnSubmit method actually does?
Thank you in advance for your help.
linq-to-sql
add a comment |
up vote
0
down vote
favorite
Suppose that I inserted an entity to an entity set by calling the InsertOnSubmit method , like this :
DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
// db.SubmitChanges();
I didnt call SubmitChanges intentionally .
My question is , can i later find that product and delete it with DeleteOnSubmit method?:
Product product = db.Products.Single(p => p.ID == "1");
db.Products.DeleteOnSubmit(product);
If i cannot , then what the InsertOnSubmit method actually does?
Thank you in advance for your help.
linq-to-sql
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Suppose that I inserted an entity to an entity set by calling the InsertOnSubmit method , like this :
DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
// db.SubmitChanges();
I didnt call SubmitChanges intentionally .
My question is , can i later find that product and delete it with DeleteOnSubmit method?:
Product product = db.Products.Single(p => p.ID == "1");
db.Products.DeleteOnSubmit(product);
If i cannot , then what the InsertOnSubmit method actually does?
Thank you in advance for your help.
linq-to-sql
Suppose that I inserted an entity to an entity set by calling the InsertOnSubmit method , like this :
DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
// db.SubmitChanges();
I didnt call SubmitChanges intentionally .
My question is , can i later find that product and delete it with DeleteOnSubmit method?:
Product product = db.Products.Single(p => p.ID == "1");
db.Products.DeleteOnSubmit(product);
If i cannot , then what the InsertOnSubmit method actually does?
Thank you in advance for your help.
linq-to-sql
linq-to-sql
asked 2 days ago
Văn Hữu
104
104
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.
My question is , can i later find that product and delete it with DeleteOnSubmit method?:
You won't be able to find the entity because it does not exist in the database.
Note, if you leave out the find, ie if your code was
DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
db.Products.DeleteOnSubmit(product);
Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.
My question is , can i later find that product and delete it with DeleteOnSubmit method?:
You won't be able to find the entity because it does not exist in the database.
Note, if you leave out the find, ie if your code was
DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
db.Products.DeleteOnSubmit(product);
Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.
add a comment |
up vote
0
down vote
The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.
My question is , can i later find that product and delete it with DeleteOnSubmit method?:
You won't be able to find the entity because it does not exist in the database.
Note, if you leave out the find, ie if your code was
DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
db.Products.DeleteOnSubmit(product);
Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.
add a comment |
up vote
0
down vote
up vote
0
down vote
The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.
My question is , can i later find that product and delete it with DeleteOnSubmit method?:
You won't be able to find the entity because it does not exist in the database.
Note, if you leave out the find, ie if your code was
DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
db.Products.DeleteOnSubmit(product);
Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.
The InsertOnSubmit method adds the entity to a list of entities which will be inserted when you call SubmitChanges.
My question is , can i later find that product and delete it with DeleteOnSubmit method?:
You won't be able to find the entity because it does not exist in the database.
Note, if you leave out the find, ie if your code was
DBDataContext db = new DBDataContext();
Product product = new Product {ID = "1" , Name = "Chair"};
db.Products.InsertOnSubmit(product);
db.Products.DeleteOnSubmit(product);
Then this would work as it wouldn't go near the database. The DeleteOnSubmit command would remove `product' from the list of entities to be inserted when you call SubmitChanges.
answered 17 hours ago
sgmoore
11.8k43058
11.8k43058
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350239%2flinq-to-sql-insertonsubmit-without-submitchanges%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown