Example #1
0
        static async Task UpdateEntityLoadedInDifferentContext()
        {
            using (var context = new PersistenceContext())
            {
                var appleCard = await FindGiftCardById(Guid.Parse(AppleCardId));

                appleCard.SetProviderName("Apple Store Gift Card");
                context.Attach(appleCard);
                context.Entry(appleCard.ExpiryDate).State = EntityState.Detached;
                appleCard.SetExpirationDate(ExpirationDate.Create(DateTime.UtcNow.AddMonths(2)).Value);
                context.Entry(appleCard.ExpiryDate).State = EntityState.Modified;
                context.Entry(appleCard).State            = EntityState.Modified;

                await context.SaveChanges();
            }
        }