当前位置: 首页>>代码示例>>C#>>正文


C# IDataStoreKey类代码示例

本文整理汇总了C#中IDataStoreKey的典型用法代码示例。如果您正苦于以下问题:C# IDataStoreKey类的具体用法?C# IDataStoreKey怎么用?C# IDataStoreKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IDataStoreKey类属于命名空间,在下文中一共展示了IDataStoreKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Delete

        public static void Delete(MySQLDataStoreBase store, MySqlConnection cnn, ModelBase instance, IDataStoreKey key, object[] extra)
        {
            var record = GeneratorUtils.AsSuitableRecordInstance(instance, true);

              using (var cmd = cnn.CreateCommand())
              {
            var pk = key ?? record.DataStoreKey;

            if (pk == null)
              throw new MySQLDataAccessException(StringConsts.KEY_UNAVAILABLE_ERROR);

            var where = GeneratorUtils.KeyToWhere(pk, cmd.Parameters);

              if (!string.IsNullOrEmpty(where))
            cmd.CommandText = string.Format("DELETE T1 FROM `{0}` T1 WHERE {1}", record.TableName, where);
              else
            cmd.CommandText = string.Format("DELETE T1 FROM `{0}` T1", record.TableName);

            var affected = 0;
            try
            {
            affected = cmd.ExecuteNonQuery();
            GeneratorUtils.LogCommand(store.LogLevel, "rmdelete-ok", cmd, null);
            }
            catch(Exception error)
            {
            GeneratorUtils.LogCommand(store.LogLevel, "rmdelete-error", cmd, error);
            throw;
            }

            if (affected == 0)
              throw new MySQLDataAccessException(string.Format(StringConsts.NO_ROWS_AFFECTED_ERROR, "Delete"));

              }//using command
        }
开发者ID:vlapchenko,项目名称:nfx,代码行数:35,代码来源:RecordModelGenerator.cs

示例2: Load

        /// <summary>
        /// Auto generates select sql and params. If sqlStatement!=null then params are added to that statement
        /// </summary>
        public static void Load(MySQLDataStoreBase store, MySqlConnection cnn, string sqlStatement, ModelBase instance, IDataStoreKey key, object[] extra)
        {
            var autoSql = string.IsNullOrEmpty(sqlStatement);

            var record = GeneratorUtils.AsSuitableRecordInstance(instance, autoSql);

            var select = new StringBuilder();

              if (autoSql)
              {
            foreach (var fld in record.Fields)
              if (fld.StoreFlag == StoreFlag.LoadAndStore || fld.StoreFlag == StoreFlag.OnlyLoad)
            select.AppendFormat(" T1.`{0}`,", fld.FieldName);

            if (select.Length > 0)
              select.Remove(select.Length - 1, 1);// remove ","
            else throw new MySQLDataAccessException(StringConsts.LOAD_NO_SELECT_COLUMNS_ERROR);

              }

              var pk = key ?? record.DataStoreKey;

              if (pk == null)
            throw new MySQLDataAccessException(StringConsts.KEY_UNAVAILABLE_ERROR);

              using (var cmd = cnn.CreateCommand())
              {

            var where = GeneratorUtils.KeyToWhere(pk, cmd.Parameters);

            if (autoSql)
              cmd.CommandText = string.Format("SELECT {0} FROM `{1}` T1 WHERE {2}", select, record.TableName, where);
            else
              cmd.CommandText = string.Format(sqlStatement, where);

            MySqlDataReader reader = null;
            try
            {
            reader = cmd.ExecuteReader();
            GeneratorUtils.LogCommand(store.LogLevel, "rmload-ok", cmd, null);
            }
            catch(Exception error)
            {
            GeneratorUtils.LogCommand(store.LogLevel, "rmload-error", cmd, error);
            throw;
            }

            using (reader)
            {
              if (reader.Read())
            reader.CopyFieldsToRecordFields(record);
              else
            throw new MySQLDataAccessException(string.Format(StringConsts.LOADING_ENTITY_NOT_FOUND_ERROR, pk));
            }//using reader

              }//using command
        }
开发者ID:vlapchenko,项目名称:nfx,代码行数:60,代码来源:RecordModelGenerator.cs

示例3: CRUDDelete

 public static int CRUDDelete(MySQLDataStoreBase store, MySqlConnection cnn, MySqlTransaction trans, Row row, IDataStoreKey key)
 {
     try
     {
     return crudDelete(store, cnn, trans, row, key);
     }
     catch(Exception error)
     {
        throw new MySQLDataAccessException(StringConsts.CRUD_STATEMENT_EXECUTION_ERROR.Args("delete", error.ToMessageWithType(), error), error);
     }
 }
开发者ID:yhhno,项目名称:nfx,代码行数:11,代码来源:CRUDGenerator.cs

示例4: KeyToWhere

        public static string KeyToWhere(IDataStoreKey key, MySqlParameterCollection parameters)
        {
            string where = null;

              if (key is CounterDataStoreKey)
              {
            where = "T1.COUNTER = ?CTR";
            var par = new MySqlParameter();
            par.ParameterName = "?CTR";
            par.Value = ((CounterDataStoreKey)key).Counter;

            parameters.Add(par);
              }
              else
              if (key is GDID)
              {
            where = "T1.GDID = ?CTR";
            var par = new MySqlParameter();
            par.ParameterName = "?CTR";
            par.Value = key;

            parameters.Add(par);
              }
              else
            if (key is NameValueDataStoreKey)
            {
              var dict = key as NameValueDataStoreKey;
              var s = new StringBuilder();
              var idx = 0;

              foreach (var e in dict)
              {
                s.AppendFormat(" (T1.`{0}` = ?P{1}) AND", e.Key, idx);
                var par = new MySqlParameter();
                par.ParameterName = "?P" + idx.ToString();
                par.Value = e.Value;
                parameters.Add(par);

                idx++;
              }

              if (s.Length > 0) s.Remove(s.Length - 3, 3);//cut "AND"

              where = s.ToString();
            }
            else
              throw new MySQLDataAccessException(StringConsts.INVALID_KEY_TYPE_ERROR);

              return where;
        }
开发者ID:itadapter,项目名称:nfx,代码行数:50,代码来源:GeneratorUtils.cs

示例5: CRUDUpdate

 public static int CRUDUpdate(MySQLDataStoreBase store, MySqlConnection cnn, MySqlTransaction trans, Row row, IDataStoreKey key, FieldFilterFunc filter)
 {
     try
     {
     return crudUpdate(store, cnn, trans, row, key, filter);
     }
     catch(Exception error)
     {
        throw new MySQLDataAccessException(
                  StringConsts.CRUD_STATEMENT_EXECUTION_ERROR.Args("update",
                  error.ToMessageWithType(), error),
                  error,
                  KeyViolationKind.Unspecified,
                  keyViolationName(error)
                  );
     }
 }
开发者ID:yhhno,项目名称:nfx,代码行数:17,代码来源:CRUDGenerator.cs

示例6: Delete

        public static void Delete(SqlConnection cnn, ModelBase instance, IDataStoreKey key, object[] extra)
        {
            var record = asSuitableRecordInstance(instance, true);

              using (var cmd = cnn.CreateCommand())
              {
              var pk = key ?? record.DataStoreKey;

              if (pk == null)
            throw new MsSQLDataAccessException(StringConsts.KEY_UNAVAILABLE_ERROR);

              var where = keyToWhere(pk, cmd.Parameters);

              if (!string.IsNullOrEmpty(where))
            cmd.CommandText = string.Format("DELETE T1 FROM [{0}] T1 WHERE {1}", record.TableName, where);
              else
            cmd.CommandText = string.Format("DELETE T1 FROM [{0}] T1", record.TableName);

             if (cmd.ExecuteNonQuery() == 0)
               throw new MsSQLDataAccessException(string.Format(StringConsts.NO_ROWS_AFFECTED_ERROR, "Delete"));

              }//using command
        }
开发者ID:vlapchenko,项目名称:nfx,代码行数:23,代码来源:MsSQLStatementGenerator.cs

示例7: Delete

 public int Delete(Row row, IDataStoreKey key = null)
 {
     CheckOpenStatus("Delete");
             return DoDelete(row, key);
 }
开发者ID:itadapter,项目名称:nfx,代码行数:5,代码来源:CRUDTransaction.cs

示例8: DoUpdate

 /// <summary>
 /// Performs CRUD row update. Override to do custom update
 /// </summary>
 protected internal virtual int DoUpdate(MySqlConnection cnn, MySqlTransaction transaction, Row row, IDataStoreKey key = null)
 {
     checkReadOnly(row.Schema, "update");
     return CRUDGenerator.CRUDUpdate(this, cnn, transaction, row, key);
 }
开发者ID:vlapchenko,项目名称:nfx,代码行数:8,代码来源:MySQLDataStore.cs

示例9: Delete

 public int Delete(Row row, IDataStoreKey key = null)
 {
     using (var cnn = GetConnection())
       return DoDelete(cnn,  null, row);
 }
开发者ID:sqlBender,项目名称:nfx,代码行数:5,代码来源:MySQLDataStore.cs

示例10: Save

        public static void Save(SqlConnection cnn, ModelBase instance, IDataStoreKey key, object[] extra)
        {
            var record = asSuitableRecordInstance(instance, true);

              if (record.LastPostedChange!=ChangeType.Created && record.LastPostedChange!=ChangeType.Edited)
            throw new MsSQLDataAccessException(string.Format(StringConsts.MODEL_INVALID_STATE_ERROR, "Created || Edited", instance.LastPostedChange));

              bool insert = instance.LastPostedChange==ChangeType.Created;

              var cnames = new StringBuilder();
              var values = new StringBuilder();
              var vparams = new List<SqlParameter>();
              var vpidx = 0;
              foreach (var fld in record.Fields)
            if (fld.StoreFlag == StoreFlag.LoadAndStore || fld.StoreFlag == StoreFlag.OnlyStore)
             if (
              insert || fld.Modified
            )
             {
               cnames.AppendFormat(" [{0}],", fld.FieldName);
               if (fld.HasValue)
               {
             var pname = string.Format("@VAL{0}", vpidx);

             if (insert)
               values.AppendFormat(" {0},", pname);
             else
               values.AppendFormat(" [{0}] = {1},", fld.FieldName, pname);

             var par = new SqlParameter();
             par.ParameterName = pname;
             par.Value = fld.ValueAsObject;
             vparams.Add(par);

             vpidx++;
               }
               else
               {
             if (insert)
               values.Append(" NULL,");
             else
               values.AppendFormat(" [{0}] = NULL,", fld.FieldName);
               }
             }

              if (cnames.Length > 0)
              {
            cnames.Remove(cnames.Length - 1, 1);// remove ","
            if (values.Length > 0) values.Remove(values.Length - 1, 1);// remove ","
              }
              else
            return;//nothing has been modified

              using (var cmd = cnn.CreateCommand())
              {
            var sql = string.Empty;

            if (insert) //INSERT
            {
            sql =
                 string.Format("INSERT INTO [{0}] ({1}) VALUES ({2})", record.TableName, cnames, values);
            }
            else //UPDATE
            {
              var pk = key ?? record.DataStoreKey;

              if (pk == null)
            throw new MsSQLDataAccessException(StringConsts.KEY_UNAVAILABLE_ERROR);

              var where = keyToWhere(pk, cmd.Parameters);

              if (!string.IsNullOrEmpty(where))
               sql = string.Format("UPDATE [{0}] T1  SET {1} WHERE {2}", record.TableName, values, where);
              else
               sql = string.Format("UPDATE [{0}] T1  SET {1}", record.TableName, values);
            }

            cmd.CommandText = sql;
            cmd.Parameters.AddRange(vparams.ToArray());

            if (cmd.ExecuteNonQuery()==0)
              throw new MsSQLDataAccessException(string.Format(StringConsts.NO_ROWS_AFFECTED_ERROR, instance.LastPostedChange == ChangeType.Created ? "Insert":"Update"));

              }//using command
        }
开发者ID:vlapchenko,项目名称:nfx,代码行数:85,代码来源:MsSQLStatementGenerator.cs

示例11: crudDelete

        private static int crudDelete(MySQLDataStoreBase store, MySqlConnection cnn, MySqlTransaction trans, Row row, IDataStoreKey key)
        {
            var target = store.TargetName;
              string tableName = getTableName(row.Schema, target);

              using (var cmd = cnn.CreateCommand())
              {
            var pk = key ?? row.GetDataStoreKey(target);

            if (pk == null)
            throw new MySQLDataAccessException(StringConsts.KEY_UNAVAILABLE_ERROR);

            var where = GeneratorUtils.KeyToWhere(pk, cmd.Parameters);

            cmd.Transaction = trans;
            if (!string.IsNullOrEmpty(where))
            cmd.CommandText = string.Format("DELETE T1 FROM `{0}` T1 WHERE {1}",tableName, where);
            else
            cmd.CommandText = string.Format("DELETE T1 FROM `{0}` T1", tableName);

            ConvertParameters(store, cmd.Parameters);

            try
            {
            var affected = cmd.ExecuteNonQuery();
            GeneratorUtils.LogCommand(store.LogLevel, "delete-ok", cmd, null);
            return affected;
            }
            catch(Exception error)
            {
            GeneratorUtils.LogCommand(store.LogLevel, "delete-error", cmd, error);
            throw;
            }

              }//using command
        }
开发者ID:yhhno,项目名称:nfx,代码行数:36,代码来源:CRUDGenerator.cs

示例12: DoUpdate

 protected abstract int DoUpdate(Row row, IDataStoreKey key, FieldFilterFunc filter = null);
开发者ID:itadapter,项目名称:nfx,代码行数:1,代码来源:CRUDTransaction.cs

示例13: DoDelete

 protected abstract int DoDelete(Row row, IDataStoreKey key);
开发者ID:itadapter,项目名称:nfx,代码行数:1,代码来源:CRUDTransaction.cs

示例14: DoUpdate

        protected virtual int DoUpdate(Connector.Database db, Row row, IDataStoreKey key)
        {
          var doc = convertRowToBSONDocumentWith_ID(row, "update");
          
          var tname = GetCollectionName(row.Schema);
          
          var collection = db[tname]; 
          
          var qry = new Connector.Query();
          qry.Set( doc[Connector.Protocol._ID] );
          var upd = new Connector.UpdateEntry(qry, doc, false, false);

          var result = collection.Update( upd );

          checkCRUDResult(result, row.Schema.Name, "update");

          return result.TotalDocumentsAffected;
        }
开发者ID:vlapchenko,项目名称:nfx,代码行数:18,代码来源:MongoDBDataStore.cs

示例15: DeleteAsync

 public virtual Task<int> DeleteAsync(Row row, IDataStoreKey key = null)
 {
     return TaskUtils.AsCompletedTask( () => this.Delete(row, key) );
 }
开发者ID:vlapchenko,项目名称:nfx,代码行数:4,代码来源:MongoDBDataStore.cs


注:本文中的IDataStoreKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。