Ejemplo n.º 1
0
        [Fact] // CodePlex 1142
        public void Explicit_loading_works_for_non_tracking_proxies_with_two_nav_props_with_different_FKs_when_one_FK_changes()
        {
            using (var context = new TwoIntoOneContext())
            {
                context.Configuration.LazyLoadingEnabled = false;

                var booking = context.BookingsNp.Find(5);

                Assert.Equal(1, booking.CreatedById);
                Assert.Equal(2, booking.ModifiedById);
                Assert.False(context.Entry(booking).Reference(b => b.CreatedBy).IsLoaded);
                Assert.False(context.Entry(booking).Reference(b => b.ModifiedBy).IsLoaded);

                booking.ModifiedById = 3;

                Assert.Equal(1, booking.CreatedById);
                Assert.Equal(3, booking.ModifiedById);
                Assert.False(context.Entry(booking).Reference(b => b.CreatedBy).IsLoaded);
                Assert.False(context.Entry(booking).Reference(b => b.ModifiedBy).IsLoaded);

                context.Entry(booking).Reference(b => b.CreatedBy).Load();
                Assert.Equal(1, context.UsersNp.Local.Count(u => u.Id == 1));
                Assert.Equal(1, booking.CreatedBy.Id);

                context.Entry(booking).Reference(b => b.ModifiedBy).Load();
                Assert.Equal(1, context.UsersNp.Local.Count(u => u.Id == 3));
                Assert.Equal(3, booking.ModifiedBy.Id);

                Assert.True(context.Entry(booking).Reference(b => b.CreatedBy).IsLoaded);
                Assert.True(context.Entry(booking).Reference(b => b.ModifiedBy).IsLoaded);
            }
        }
Ejemplo n.º 2
0
        [Fact] // CodePlex 1142
        public void Lazy_loading_works_for_non_tracking_proxies_with_two_nav_props_with_different_FKs_when_one_FK_changes()
        {
            using (var context = new TwoIntoOneContext())
            {
                var booking = context.BookingsNp.Find(5);

                Assert.Equal(1, booking.CreatedById);
                Assert.Equal(2, booking.ModifiedById);
                Assert.False(context.Entry(booking).Reference(b => b.CreatedBy).IsLoaded);
                Assert.False(context.Entry(booking).Reference(b => b.ModifiedBy).IsLoaded);

                booking.ModifiedById = 3;

                Assert.Equal(1, booking.CreatedById);
                Assert.Equal(3, booking.ModifiedById);
                Assert.False(context.Entry(booking).Reference(b => b.CreatedBy).IsLoaded);
                Assert.False(context.Entry(booking).Reference(b => b.ModifiedBy).IsLoaded);

                // Trigger lazy loading
                Assert.Equal(1, booking.CreatedBy.Id);
                Assert.Equal(3, booking.ModifiedBy.Id);

                Assert.True(context.Entry(booking).Reference(b => b.CreatedBy).IsLoaded);
                Assert.True(context.Entry(booking).Reference(b => b.ModifiedBy).IsLoaded);
            }
        }