Esempio n. 1
0
        private void ObjectSpace_CustomCommitChanges(object sender, HandledEventArgs e)
        {
            var toSave   = objectSpace.GetObjectsToSave(false);
            var toInsert = new List <object>();
            var toUpdate = new List <object>();

            foreach (var obj in toSave)
            {
                if (objectSpace.IsNewObject(obj)) // or check the object map?
                {
                    toInsert.Add(obj);
                }
                else
                {
                    toUpdate.Add(obj);
                }
            }
            var toDelete = objectSpace.GetObjectsToDelete(false);

            if (toInsert.Count != 0 || toUpdate.Count != 0 || toDelete.Count != 0)
            {
                factory.SaveObjects(toInsert, toUpdate, toDelete);
            }
            //e.Handled = false;// !!!
        }
Esempio n. 2
0
        private void ObjectSpace_Committing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            NonPersistentObjectSpace objectSpace = (NonPersistentObjectSpace)sender;

            using (IDbConnection conn = new SqlConnection("uid=sa;pwd=sa;Pooling=false;Data Source=.;Initial Catalog=SkyFaith"))
            {
                foreach (object obj in objectSpace.ModifiedObjects)
                {
                    if (obj is BusinessObjects.NonPersistentObjects.Student)
                    {
                        if (objectSpace.IsNewObject(obj))
                        {
                            conn.Execute("insert into student(Id,name,gender,phone) values(@Id,@name,@gender,@phone)", obj);
                        }
                        else if (objectSpace.IsDeletedObject(obj))
                        {
                            conn.Execute("delete from student where Id = @Id", obj);
                        }
                        else
                        {
                            conn.Execute("update student set name=@name,gender=@gender,phone=@phone where Id=@Id", obj);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 private void ObjectSpace_CustomCommitChanges(object sender, HandledEventArgs e)
 {
     foreach (var obj in objectSpace.GetObjectsToSave(false))
     {
         if (obj is Article article)
         {
             if (objectSpace.IsNewObject(obj))
             {
                 article.ID = articles.Count;
                 articles.Add(article);
             }
         }
     }
 }
Esempio n. 4
0
 private BaseNonPersistent GetObject(BaseNonPersistent obj)
 {
     return(!objectSpace.IsNewObject(obj) ? GetObjectByKey(obj.ID) : obj);
 }