Jeff-Lewis / codesmith

Automatically exported from code.google.com/p/codesmith
0 stars 0 forks source link

DataContext is not updated after InserOnSubmit #145

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Hi.

After inserting an item to the database the DataContext does not seem to 
register this. Example below illustrates the code I am using to replicate 
the problem.

1.  EntBooks.Data.EBDataContext ctx = new EntBooks.Data.EBDataContext();
2.  EntBooks.Data.ProductGroup _ProductGroup = 
ctx.Manager.ProductGroup.GetByKey(2);
3.
4.  Response.Write("<br>Options list count. " + 
_ProductGroup.ProductDeliveryOptionList.Count);
5.
6.  EntBooks.Data.ProductDeliveryOption pdo = new 
EntBooks.Data.ProductDeliveryOption();
7.  pdo.CreatedBy = User.Identity.Name;
8.  pdo.CreatedDate = DateTime.Now;
9.  pdo.DeliveryOptionID = 1;
10. pdo.IsActive = true;
11. pdo.LastModifiedBy = pdo.CreatedBy;
12. pdo.LastModifiedDate = pdo.CreatedDate;
13. pdo.ProductGroupID = _ProductGroup.Id;
14.
15. ctx.ProductDeliveryOption.InsertOnSubmit(pdo);
16. ctx.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
17.
18. Response.Write("<br>Options list count. " + 
_ProductGroup.ProductDeliveryOptionList.Count);

Both lines 4 and 18 report the same number.

What is the expected output? What do you see instead?

Lines 18 should report the number reported by line 4 plus 1

What version of the product are you using?

Plinqo 3.1.808

Please provide any additional information below.

Same code in reverse (deleting an item from ProductDeliveryOption) works 
as expected.

Original issue reported on code.google.com by oleg.put...@gmail.com on 25 Sep 2009 at 1:24

GoogleCodeExporter commented 9 years ago
Try the code below instead of line 15

_ProductGroup.ProductDeliveryOptionList.Add(pdo);
ctx.SubmitChanges();

This code should add the DeliveryOption and the result will be maintained in 
the list.

Original comment by shannon....@gmail.com on 2 Oct 2009 at 4:24

GoogleCodeExporter commented 9 years ago
Thanks for your feedback.

Yes, adding new item to object collection list rather than context list 
resolves the 
issue. 

But shouldn't it work using both approaches and why it does work when removing 
items 
e.g. both
ctx.ProductDeliveryOption.DeleteOnSubmit(pdo); 
and
_ProductGroup.ProductDeliveryOptionList.DeleteOnSubmit(pdo);
works.

Thanks,
Oleg

Original comment by oleg.put...@gmail.com on 3 Oct 2009 at 5:22