Esempio n. 1
0
        public int Update(Query query, IDictionary <string, IQueryValue> data)
        {
            var schema    = GetSchema();
            var dataClass = schema.FindClassByID(query.Table.Name);

            if (dataClass != null)
            {
                var affectedObjIds = ObjectContainerStorage.GetObjectIds(query);
                foreach (var objId in affectedObjIds)
                {
                    var obj = new ObjectContainer(dataClass, objId);
                    foreach (var entry in data)
                    {
                        var valConst = entry.Value as QConst;
                        if (valConst == null)
                        {
                            throw new NotSupportedException(
                                      String.Format("Value {0} for {1} is not supported", entry.Value, entry.Key));
                        }
                        obj[entry.Key] = valConst.Value;
                    }
                    ObjectContainerStorage.Update(obj);
                }
                return(affectedObjIds.Length);
            }
            var relation = schema.FindRelationshipByID(query.Table.Name);

            if (relation != null)
            {
                throw new NotSupportedException(String.Format("Update is not allowed for relationship {0}", relation.ID));
            }
            return(UnderlyingDalc.Update(query, data));
        }
Esempio n. 2
0
        protected void UpdateDataRow(Class dataClass, DataRow r)
        {
            var objId = Convert.ToInt64(r["id"]);
            var obj   = new ObjectContainer(dataClass, objId);

            foreach (DataColumn c in r.Table.Columns)
            {
                if (!c.AutoIncrement)
                {
                    var val = r[c];
                    if (val == DBNull.Value)
                    {
                        val = null;
                    }
                    obj[c.ColumnName] = val;
                }
            }

            ObjectContainerStorage.Update(obj);
        }