Ejemplo n.º 1
0
 public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
 {
     base.SubmitChanges(failureMode);
     if (UseExternalConnection)
     {
         ExternalTransaction.Commit();
         ExternalTransaction = ExternalConnection.BeginTransaction(ExternalTransactionName);
         base.Transaction    = ExternalTransaction;
     }
 }
Ejemplo n.º 2
0
 public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
 {
     try
     {
         base.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
     }
     catch (ChangeConflictException)
     {
         foreach (var x in this.ChangeConflicts)
         {
             x.Resolve(System.Data.Linq.RefreshMode.KeepCurrentValues);
         }
     }
 }
Ejemplo n.º 3
0
 public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
 {
     if (this.ObjectTrackingEnabled == true)
     {
         ChangeSet cs             = this.GetChangeSet();
         var       typesToCheck   = new Type[] { typeof(string), typeof(System.Data.Linq.Binary) };//, typeof(DateTime) };
         var       insertsUpdates = (
             from i in cs.Inserts.Union(cs.Updates)
             join m in this.Mapping.GetTables() on i.GetType() equals m.RowType.Type
             select new
         {
             Entity = i,
             Members = m.RowType.DataMembers.Where(dm => typesToCheck.Contains(dm.Type)).ToList()
         }).Where(m => m.Members.Any()).ToList();
         foreach (var ins in insertsUpdates)
         {
             foreach (var mm in ins.Members)
             {
                 //if (mm.DbType == "datetime NOT NULL")
                 //{
                 //    var dt = mm.MemberAccessor.GetBoxedValue(ins.Entity).ToDate();
                 //    if (dt < DateTime.Parse("1/1/1753"))
                 //    {
                 //        var iex = new InvalidOperationException(mm.Name + " in " + mm.DeclaringType.Name + " has a value that will not fit into " + mm.DbType + " " + dt.FormatDate());
                 //        throw iex;
                 //    }
                 //}
                 //else
                 {
                     var maxLength = GetMaxLength(mm.DbType);
                     if (mm.MemberAccessor.HasValue(ins.Entity))
                     {
                         var memberValueLength = GetMemberValueLength(mm.MemberAccessor.GetBoxedValue(ins.Entity));
                         if (maxLength > 0 && memberValueLength > maxLength)
                         {
                             var iex = new InvalidOperationException(mm.Name + " in " + mm.DeclaringType.Name + " has a value that will not fit into " + mm.DbType);
                             throw iex;
                         }
                     }
                 }
             }
         }
         base.SubmitChanges(failureMode);
     }
     else
     {
         base.SubmitChanges(failureMode);
     }
 }
Ejemplo n.º 4
0
 public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
 {
     TestSubmitChanges();
     base.SubmitChanges(failureMode);
 }//override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
Ejemplo n.º 5
0
 public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
 {
     // Test submit changes should throw if it encounters a problem
     TestSubmitChanges();
     base.SubmitChanges(failureMode);
 }//override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
Ejemplo n.º 6
0
        public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
        {
            System.Data.Linq.ChangeSet cs = this.GetChangeSet();
            bool Cancel = false;

            List <LinqMicajahEntitybase> Inserted = new List <LinqMicajahEntitybase>();
            List <LinqMicajahEntitybase> Updated  = new List <LinqMicajahEntitybase>();
            List <LinqMicajahEntitybase> Deleted  = new List <LinqMicajahEntitybase>();

            for (int i = 0; i < cs.Inserts.Count; i++)
            {
                object o = cs.Inserts[i];
                if (!(o is LinqMicajahEntitybase))
                {
                    continue;
                }
                LinqMicajahEntitybase entity = (LinqMicajahEntitybase)o;

                if (InstanceId != Guid.Empty)
                {
                    SetParam(entity, "InstanceId", InstanceId);
                }
                SetParam(entity, "Created", DateTime.Now);
                SetParam(entity, "Status", true);

                string PKName = GetPK(entity);
                o = GetParam(entity, PKName);
                if (o is Guid)
                {
                    if (((Guid)o) == Guid.Empty)
                    {
                        SetParam(entity, PKName, Guid.NewGuid());
                    }
                }
                entity.OnInserting(this, ref Cancel);
                Inserted.Add(entity);
            }

            for (int i = 0; i < cs.Updates.Count; i++)
            {
                object o = cs.Updates[i];
                if (!(o is LinqMicajahEntitybase))
                {
                    continue;
                }
                LinqMicajahEntitybase entity = (LinqMicajahEntitybase)o;
                SetParam(entity, "Updated", DateTime.Now);
                entity.OnUpdating(this, ref Cancel);
                Updated.Add(entity);
            }

            for (int i = 0; i < cs.Deletes.Count; i++)
            {
                object o = cs.Deletes[i];
                if (!(o is LinqMicajahEntitybase))
                {
                    continue;
                }
                LinqMicajahEntitybase entity = (LinqMicajahEntitybase)o;
                entity.OnDeleting(this, ref Cancel);
                Deleted.Add(entity);
            }

            if (!Cancel)
            {
                base.SubmitChanges(failureMode);
            }

            foreach (LinqMicajahEntitybase e in Inserted)
            {
                e.OnInserted(this);
            }
            foreach (LinqMicajahEntitybase e in Updated)
            {
                e.OnUpdated(this);
            }
            foreach (LinqMicajahEntitybase e in Deleted)
            {
                e.OnDeleted(this);
            }
        }