• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IDataStoreKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Delete

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


示例17: Update

 public virtual int Update(Row row, IDataStoreKey key = null)
 {
     var db = GetDatabase();
     return DoUpdate(db, row, key);
 }
开发者ID:vlapchenko,项目名称:nfx,代码行数:5,代码来源:MongoDBDataStore.cs


示例18: DoDelete

 protected override int DoDelete(Row row, IDataStoreKey key)
 {
     return Store.DoDelete(m_Connection, m_Transaction, row, key);
 }
开发者ID:sergey-msu,项目名称:nfx,代码行数:4,代码来源:MySQLCRUDTransaction.cs


示例19: RowChange

 public RowChange(RowChangeType type, Row row, IDataStoreKey key)
 {
     ChangeType = type;
     Row = row;
     Key = key;
 }
开发者ID:vlapchenko,项目名称:nfx,代码行数:6,代码来源:RowChanges.cs


示例20: DeleteAsync

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IDataStructureObject类代码示例发布时间:2022-05-24
下一篇:
C# IDataStoreContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap