public void Given_SurrogateKeys_When_DetailAddedToMaster_Then_DetailIsInObjectStateManager()
        {
            using (var ctx = new Model1Container())
            {
                //ctx.DeleteDatabase();
                ctx.ExecuteStoreCommand("DELETE FROM [EF4SurrogateDetail]");
                ctx.ExecuteStoreCommand("DELETE FROM [EFMasterSurrogate]");

                var master = new EFMasterSurrogate();
                master.MyProperty = "pepo";
                ctx.EFMasterSurrogate.AddObject(master);

                var detail = new EF4SurrogateDetail();
                master.EF4SurrogateDetail.Add(detail);
                Assert.IsTrue(ExistInObjectStateManager(ctx, detail));

                ctx.SaveChanges();
            }
        }
Пример #2
0
        private void FixupEFMasterSurrogate(EFMasterSurrogate previousValue)
        {
            if (previousValue != null && previousValue.EF4SurrogateDetail.Contains(this))
            {
                previousValue.EF4SurrogateDetail.Remove(this);
            }

            if (EFMasterSurrogate != null)
            {
                if (!EFMasterSurrogate.EF4SurrogateDetail.Contains(this))
                {
                    EFMasterSurrogate.EF4SurrogateDetail.Add(this);
                }
                if (Master_DbId != EFMasterSurrogate.DbId)
                {
                    Master_DbId = EFMasterSurrogate.DbId;
                }
            }
        }