public void OnChange(BRecord entity, UpdateOperations operation)
 {
     switch (operation)
     {
     case UpdateOperations.Add:
     case UpdateOperations.Change:
         entity.ChangedDate = DateTime.Now;
         break;
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            var ctx = new ConcurrencyTestDataContext();

            var entityA = new ARecord {
                Value = "[0] created payload"
            };

            ctx.ARecords.Add(entityA);
            ctx.SaveChanges();

            entityA.Value = string.Format("[1]  updated payload at {0}", DateTime.Now);
            ctx.SaveChanges();

            entityA.Value = string.Format("[2] updated payload at {0}", DateTime.Now);
            ctx.SaveChanges();


            var entityB = new BRecord {
                Value = "[0] created payload"
            };

            ctx.BRecords.Add(entityB);
            ctx.SaveChanges();

            entityB.Value = string.Format("[1]  updated payload at {0}", DateTime.Now);
            ctx.SaveChanges();

            entityB.Value = string.Format("[2] updated payload at {0}", DateTime.Now);
            ctx.SaveChanges();


            var entityC = new CRecord {
                Value = "[0] created payload"
            };

            ctx.CRecords.Add(entityC);
            ctx.SaveChanges();

            entityC.Value = string.Format("[1]  updated payload at {0}", DateTime.Now);
            ctx.SaveChanges();

            entityC.Value = string.Format("[2] updated payload at {0}", DateTime.Now);
            ctx.SaveChanges();


            var newContext = new ConcurrencyTestDataContext();

            entityC.Value = string.Format("[3] updated payload at {0} via new data context", DateTime.Now);
            newContext.Attach(entityC);

            newContext.SaveChanges();
        }
Exemple #3
0
 public FrmOperationRecord(AdminMsg LoginMsg)
 {
     InitializeComponent();
     BRecord = new BRecord(LoginMsg.SqlConn);
     TheUser = LoginMsg;
 }
Exemple #4
0
 private void OnDetach(BRecord entity)
 {
 }
Exemple #5
0
 public void Detach(BRecord entity)
 {
     BRecords.Detach(entity);
 }
Exemple #6
0
        private BRecord AttachWithRelations(BRecord entity, InsertMode insertMode = InsertMode.Attach, MergeOption mergeOption = MergeOption.AppendOnly, List <object> referenceTrackingList = null)
        {
            #region iteration tracking

            if (ReferenceEquals(null, referenceTrackingList))
            {
                referenceTrackingList = new List <object>();
            }

            if (referenceTrackingList.Contains(entity))
            {
                return(_bRecords.GetExisting(entity));
            }
            else
            {
                referenceTrackingList.Add(entity);
            }

            #endregion

            #region add/attach entity

            BRecord existingEntity = null;

            switch (insertMode)
            {
            case InsertMode.Add:
                existingEntity = _bRecords.Add(entity);
                break;

            case InsertMode.Attach:
                existingEntity = _bRecords.Attach(entity);
                break;

            default:
                throw new Exception(string.Format("Implementation Exception: missing action for {0}", insertMode));
            }

            if (!ReferenceEquals(null, existingEntity) && ReferenceEquals(existingEntity, entity))
            {
                return(existingEntity);
            }

            #endregion

            #region attach relations recursively


            #endregion

            #region refresh existing entity based on merge options

            if (!ReferenceEquals(null, existingEntity) && !ReferenceEquals(existingEntity, entity))
            {
                if (BRecords.MergeOption == MergeOption.OverwriteChanges)
                {
                    Invoke(delegate
                    {
                        existingEntity.Refresh(entity, trackChanges: false);
                        existingEntity.AcceptChanges();
                    });
                }
                else if (BRecords.MergeOption == MergeOption.PreserveChanges)
                {
                    Invoke(delegate
                    {
                        existingEntity.Refresh(entity, trackChanges: false, preserveExistingChanges: true);
                    });
                }
            }

            #endregion

            return(existingEntity);
        }
Exemple #7
0
 public void AttachAsModified(BRecord entity, BRecord original)
 {
     BRecords.AttachAsModified(entity, original);
 }
Exemple #8
0
 public void Attach(BRecord entity)
 {
     BRecords.Attach(entity);
 }
Exemple #9
0
 public void Delete(BRecord entity)
 {
     BRecords.Delete(entity);
 }
Exemple #10
0
 public void Add(BRecord entity)
 {
     BRecords.Add(entity);
 }
Exemple #11
0
 public Point(BRecord brec)
 {
     Latitude  = brec.Latitude;
     Longitude = brec.Longitude;
     Altitude  = brec.GnssAltitude;
 }