Exemplo n.º 1
0
        public void Test_null_on_EF_Repo()
        {
            var db = new EfDbMapper("Data Source=localhost; Initial Catalog=ServiceStackNtierDemo; User id=sa; Password=P@$$w0rd");

            var repo = new Ienablemuch.ToTheEfnhX.EntityFramework.Repository<Order>(db);

            // Order o = db.Set<Order>().Single(x => x.OrderId == 1);
            Order o = repo.GetEager(1);

            // what a work-around!
            // http://www.codetuning.net/blog/post/Understanding-Entity-Framework-Associations.aspx

            // var dummy = o.Customer;

            // we fix the null-assign problem on Get. we dummy-read all the possible Independent Associations, i.e. all reference types
            o.Customer = null;

            Assert.IsNull(o.Customer); // without the: var dummy = o.Customer, IsNull fails

            repo.Save(o);
        }
Exemplo n.º 2
0
        public void Test_null_on_EF_Repo_via_dto()
        {
            var db = new EfDbMapper("Data Source=localhost; Initial Catalog=ServiceStackNtierDemo; User id=sa; Password=P@$$w0rd");

            var repo = new Ienablemuch.ToTheEfnhX.EntityFramework.Repository <Order>(db);

            // Order o = db.Set<Order>().Single(x => x.OrderId == 1);
            Order o = repo.Get(1);

            var dto = Mapper.ToDto <Order, OrderDto>(o);

            // what a work-around!
            // http://www.codetuning.net/blog/post/Understanding-Entity-Framework-Associations.aspx

            dto.CustomerId = 0;

            var newPoco = Mapper.ToPoco <OrderDto, Order>(dto);

            repo.AssignStub(newPoco);

            repo.Save(newPoco);
        }
Exemplo n.º 3
0
        public void Test_null_on_EF_Repo()
        {
            var db = new EfDbMapper("Data Source=localhost; Initial Catalog=ServiceStackNtierDemo; User id=sa; Password=P@$$w0rd");

            var repo = new Ienablemuch.ToTheEfnhX.EntityFramework.Repository <Order>(db);

            // Order o = db.Set<Order>().Single(x => x.OrderId == 1);
            Order o = repo.GetEager(1);

            // what a work-around!
            // http://www.codetuning.net/blog/post/Understanding-Entity-Framework-Associations.aspx


            // var dummy = o.Customer;

            // we fix the null-assign problem on Get. we dummy-read all the possible Independent Associations, i.e. all reference types
            o.Customer = null;

            Assert.IsNull(o.Customer); // without the: var dummy = o.Customer, IsNull fails


            repo.Save(o);
        }
Exemplo n.º 4
0
        public void Test_null_on_EF_Repo_via_dto()
        {
            var db = new EfDbMapper("Data Source=localhost; Initial Catalog=ServiceStackNtierDemo; User id=sa; Password=P@$$w0rd");

            var repo = new Ienablemuch.ToTheEfnhX.EntityFramework.Repository<Order>(db);

            // Order o = db.Set<Order>().Single(x => x.OrderId == 1);
            Order o = repo.Get(1);

            var dto = Mapper.ToDto<Order, OrderDto>(o);

            // what a work-around!
            // http://www.codetuning.net/blog/post/Understanding-Entity-Framework-Associations.aspx

            dto.CustomerId = 0;

            var newPoco = Mapper.ToPoco<OrderDto, Order>(dto);
            repo.AssignStub(newPoco);

            repo.Save(newPoco);
        }