Exemple #1
0
 public void Add(object entity)
 {
     //断言参入的参数为null或者空字符串(RErrorCode.NullReference - 0x00000001)
     PreconditionAssert.IsNotNull(entity, ErrorMessages.NullReferenceException);
     ORMHelper.EntityIsMappingDatabase(entity.GetType(), ErrorMessages.EntityMappingError);
     ORMHelper.CheckEntityIsNotReadOnly(entity.GetType(), ErrorMessages.EntityReadOnly);
     try
     {
         InsertCommandCreator icc = new InsertCommandCreator(dbAccess);
         icc.Entity = entity;
         DbCommand dbCommand = icc.GetDbCommand();
         dbAccess.ExecCommand(dbCommand);
     }
     catch (Exception ex)
     {
         throw new ORMException("Add entity failed, detail:\n\t" + ORMHelper.GetEntityInfoMessage(entity), ex);
     }
 }
Exemple #2
0
        public void Modify(object entity)
        {
            PreconditionAssert.IsNotNull(entity, ErrorMessages.NullReferenceException);
            ORMHelper.EntityIsMappingDatabase(entity.GetType(), ErrorMessages.EntityMappingError);
            ORMHelper.CheckEntityIsNotReadOnly(entity.GetType(), ErrorMessages.EntityReadOnly);

            try
            {
                ModifyCommandCreator mcc = new ModifyCommandCreator(dbAccess);
                mcc.Entity = entity;
                DbCommand dbCommand = mcc.GetDbCommand();
                dbAccess.ExecCommand(dbCommand);
            }
            catch (Exception ex)
            {
                throw new ORMException("Update entity failed, detail:\n\t" + ORMHelper.GetEntityInfoMessage(entity), ex);
            }
        }