Menu

Modified object persistence

James
2006-09-02
2013-04-22
  • James

    James - 2006-09-02

    Please suggest what's wrong with my code.

    I can successfuly retrive object hierarchy (e.g. grandparent->parent->child), lazy loading works just fine. However, I can't figure out what I'm doing wrong with persisting my hierarchy - no update queries been sent. I tried different approaches, this one is the last one (should be compliant with practices outlined in this forum):

        class Program {
            static void Main(string[] args) {
                TestFacade facade = new TestFacade();

                Level1 l1 = (Level1)facade.New();

                Console.WriteLine("l1.Level1Name: " + l1.Level1Name);

                l1.Level1Name = "value changed";

                Console.WriteLine("l1.IsEdited? " + l1.IsEdited);//returns true
               
                facade.Store(l1);

                Console.WriteLine("l1.IsEdited? " + l1.IsEdited);//returns true
            }
        }
        [Transaction(TransactionOption.Required)]
        public sealed class TestFacade : Service<TestFacade> {
            public EditableObject New() {
                return QueryFacade.FindObjectByPrimaryKey<Level1>(1);//sucessfuly retrieves from db
            }
            public void Store(EditableObject eo) {
                BindUtil.BindToTransaction(eo);//nothing happens
            }
        }

     
    • Richard Beauchamp

      Hi James,

      You have to get the instance of TestFacade via 'TestFacade.Instance' not 'new TestFacade()'.

       
    • James

      James - 2006-09-04

      Thank you, it works!

       

Log in to post a comment.