Beispiel #1
0
        public int AddInspection(InspectionPoco inspectionPoco)
        {
            using (var db = new MemoryContext())
            {
                db.InspectionDbSet.Add(inspectionPoco);

                db.SaveChanges();

                _getInMemory++;
                return(inspectionPoco.InspectionId);
            }
        }
Beispiel #2
0
        public void QueryInMemory()
        {
            var inspectionRepository = _service.GetInMemoryEFCoreInspectionRepository();

            var inspectionPoco = new InspectionPoco()
            {
                StadiumId = 34,
                StadiumInformationComment = "Something to comment on ..."
            };

            var inspectionId1 = inspectionRepository.AddInspection(inspectionPoco);

            inspectionId1.Should().BeGreaterThan(0);
        }
Beispiel #3
0
        public void UpsertInspectionRage(IEnumerable <int> inspectionIds)
        {
            using (var db = new EfContext())
            {
                var pocos = new List <InspectionPoco>();

                DisplayStates(db.ChangeTracker.Entries());

                foreach (var inspectionId in inspectionIds)
                {
                    // try to retrieve existing entity
                    var retrieveInspectionPoco = db.InspectionDbSet.Find(inspectionId);

                    // if entity does not already exist -> create new
                    if (retrieveInspectionPoco == null)
                    {
                        retrieveInspectionPoco = new InspectionPoco();

                        db.InspectionDbSet.Add(retrieveInspectionPoco);
                    }

                    //Example to remove a record
                    //if (inspectionId == 685)
                    //{
                    //    db.InspectionDbSet.Remove(retrieveInspectionPoco);

                    //}

                    //if necessary, set the properties or map received values
                    retrieveInspectionPoco.StatusInspection = 2;
                }

                // EntityState should be set automatically by EF ChangeTracker
                // you can see all the operation during the save changes
                DisplayStates(db.ChangeTracker.Entries());


                var resp = db.SaveChanges();
            }
        }
Beispiel #4
0
        public void UpsertInspection(InspectionPoco poco)
        {
            using (var db = new EfContext())
            {
                db.Entry(poco).State = poco.InspectionId > 0 ? EntityState.Modified : EntityState.Added;

                var resp = db.SaveChanges();

                //db.Entry(poco).Property("StatusInspection").IsModified = true;

                //db.ChangeTracker.TrackGraph(poco, e => {
                //    if (e.Entry.IsKeySet)
                //    {
                //        e.Entry.State = EntityState.Modified;
                //    }
                //    else
                //    {
                //        e.Entry.State = EntityState.Added;
                //    }
                //});
            }
        }