Exemplo n.º 1
0
        private static async Task EFCoreCreateAsync(DatabaseAccessRequest databaseAccessRequest)
        {
            using (var context = new EfPocEntitiesEFCore(databaseAccessRequest))
            {
                using (var transaction = context.Database.BeginTransaction(IsolationLevel.RepeatableRead))
                {
                    try
                    {
                        var member = new Members
                        {
                            FirstName      = "FirstName",
                            LastName       = "LastName",
                            HIC            = "HIC0001",
                            PlanID         = "Plan",
                            PBP            = "PBP",
                            SegmentID      = "SEG",
                            CurrentEffDate = DateTime.Now
                        };
                        context.Members.Add(member);
                        await context.SaveChangesAsync();

                        var span = new Models.Spans
                        {
                            MemberId  = member.Id,
                            SpanType  = "SECD",
                            SpanValue = "123",
                            StartDate = DateTime.Now
                        };
                        context.Spans.Add(span);
                        await context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        transaction.Rollback();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static async Task EFCoreChangeTrackerAsync(DatabaseAccessRequest databaseAccessRequest)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;

            using (var context = new EfPocEntitiesEFCore(databaseAccessRequest))
            {
                Stopwatch w = new Stopwatch();
                w.Start();
                Console.WriteLine("Change Tracker");

                var member = new Members
                {
                    FirstName      = "FirstName",
                    LastName       = "LastName",
                    HIC            = "HIC0001",
                    PlanID         = "Plan",
                    PBP            = "PBP",
                    SegmentID      = "SEG",
                    CurrentEffDate = DateTime.Now
                };

                var span = new Models.Spans
                {
                    MemberId  = member.Id,
                    SpanType  = "SECD",
                    SpanValue = "111",
                    StartDate = DateTime.Now
                };
                var newspan = new Models.Spans
                {
                    MemberId  = member.Id,
                    SpanType  = "SECD",
                    SpanValue = "222",
                    StartDate = DateTime.Now
                };

                member.Spans.Add(span);
                member.Spans.Add(newspan);

                context.Members.Add(member);

                var member1 = new Members
                {
                    FirstName      = "FirstName1",
                    LastName       = "LastName1",
                    HIC            = "HIC0001",
                    PlanID         = "Plan",
                    PBP            = "PBP",
                    SegmentID      = "SEG",
                    CurrentEffDate = DateTime.Now
                };

                var span1 = new Models.Spans
                {
                    MemberId  = member1.Id,
                    SpanType  = "SECD",
                    SpanValue = "123",
                    StartDate = DateTime.Now
                };

                member1.Spans.Add(span1);

                context.Members.Add(member1);

                await SaveChangesExtendedAsync(context.ChangeTracker.Entries(), context);
            }
        }