Esempio n. 1
0
        public void Update <TDataObject>(IList <TDataObject> objs)
            where TDataObject : class, IIntKeyedDataObject, new()
        {
            //TODO: Update cache here. not only delete cached items
            if (objs.Count > 0)
            {
                using (var scope = DBScope("Updating multiple " + typeof(TDataObject).Name + ". Count = " + objs.Count))
                {
                    RunInTransaction(scope.Connection, (cn, transaction) =>
                    {
                        using (var cmd = cn.CreateCommand())
                        {
                            var sc = new SqlSerializationContext((SqlCommand)cmd);
                            foreach (var o in objs)
                            {
                                DataObjectSqlSerializer <TDataObject> .AppendUpdateSql(sc, o);
                                Logger.WriteLine("ID = " + o.ID);
                                sc.Next();
                                CacheIt(o);
                            }
                            sc.Finish();

                            cmd.Transaction = transaction;
                            cmd.LexExecuteNonQuery();
                        }
                    });
                }
            }
        }
Esempio n. 2
0
        public void Update <TDataObject>(TDataObject obj)
            where TDataObject : class, IIntKeyedDataObject, new()
        {
            using (var scope = DBScope("Updating " + typeof(TDataObject).Name))
            {
                using (var cmd = scope.Connection.CreateCommand())
                {
                    var sc = new SqlSerializationContext(cmd);
                    DataObjectSqlSerializer <TDataObject> .AppendUpdateSql(sc, obj);

                    sc.Finish();
                    cmd.LexExecuteNonQuery();
                }
                CacheIt(obj);
            }
        }