Exemplo n.º 1
0
        private void insert(DbIdentityRecordInfo info, object data)
        {
            DbFieldInfo primaryKey = info.PrimaryKey;

            if (primaryKey.FieldType == typeof(Guid))
            {
                Guid guid = Guid.NewGuid();
                primaryKey.SetValue(data, guid);

                object[] values = info.GetValues(data, primaryKey.Name, guid);
                Accessor.Insert(info.TableName, values);
            }
            else
            if (!info.IsDbGeneratedPrimaryKey)
            {
                object[] values = info.GetValues(data, primaryKey.Name, primaryKey.GetValue(data));
                Accessor.Insert(info.TableName, values);
            }
            else
            {
                object[] values = info.GetValues(data);
                object   newId  = Accessor.InsertIdentity(info.TableName, primaryKey.Name, values);
                primaryKey.SetValue(data, Convert.ChangeType(newId, primaryKey.FieldType));
            }
        }
Exemplo n.º 2
0
        private int update(DbIdentityRecordInfo info, object data)
        {
            if (!info.IsPrimaryKeyValid(data))
            {
                throw new NdbException(string.Format(
                                           "Primary Key wasn't set for the {0} object", data.GetType()));
            }

            return(Accessor.Update(info.TableName, info.GetValues(data),
                                   info.PrimaryKey.Name, info.PrimaryKey.GetValue(data)));
        }