Example #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);
     }
 }