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


C# IDbContext.Sql方法代码示例

本文整理汇总了C#中IDbContext.Sql方法的典型用法代码示例。如果您正苦于以下问题:C# IDbContext.Sql方法的具体用法?C# IDbContext.Sql怎么用?C# IDbContext.Sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDbContext的用法示例。


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

示例1: dateplus

 //日期时间加上N位数字加一
 public static string dateplus(IDbContext db, string table, string field,string datestringFormat,int numberLength)
 {
     var dbkey = db.Sql(String.Format("select isnull(max({0}),0) from {1}", field, table)).QuerySingle<string>();
     var mykey = DateTime.Now.ToString(datestringFormat) + string.Empty.PadLeft(numberLength, '0');
     var cachedKeys = getCacheKey(table, field);
     var currentKey = maxOfAllKey(cachedKeys, ZConvert.ToString(dbkey), mykey);
     var key = ZConvert.ToString(currentKey + 1);
     SetCacheKey(table, field, key);
     return key;
 }
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:11,代码来源:NewKey.cs

示例2: maxplus

 //最大值加一
 public static string maxplus(IDbContext db, string table, string field, ParamQuery pQuery)
 {
     //var where = pQuery.GetData().WhereSql;
     var sqlWhere = " where 1 = 1 ";
     if (pQuery != null)
         sqlWhere += " and " +  pQuery.GetData().WhereSql;
     var dbkey = db.Sql(String.Format("select isnull(max({0}),0) from {1} {2}", field, table, sqlWhere)).QuerySingle<string>();
     var cachedKeys = getCacheKey(table, field);
     var currentKey = maxOfAllKey(cachedKeys, ZConvert.ToString(dbkey));
     var key = ZConvert.ToString(currentKey + 1);
     SetCacheKey(table, field, key);
     return key;
 }
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:14,代码来源:NewKey.cs

示例3: maxplus

        //最大值加一
        public static string maxplus(IDbContext db, string table, string field, ParamQuery pQuery)
        {
            var sqlWhere = " where 1 = 1 ";
 
            if (pQuery != null)
            {
                var conditions = pQuery.GetData().Where;
                conditions.ForEach(c => sqlWhere += c.ToSql( GetDbType(db), !string.IsNullOrWhiteSpace(sqlWhere)));
            }

            var dbkey = db.Sql(String.Format("select {{isnull,max({0}),0}} from {1} {2}", field, table, sqlWhere)).QuerySingle<string>();
            var cachedKeys = getCacheKey(table, field);
            var currentKey = maxOfAllKey(cachedKeys, ConvertHelper.ToString(dbkey));
            var key = ConvertHelper.ToString(currentKey + 1);
            SetCacheKey(table, field, key);
            return key;
        }
开发者ID:uwitec,项目名称:web-mvc-logistics,代码行数:18,代码来源:NewKey.cs

示例4: LoadReferences

        /// <summary>
        /// Loads destination records referenced by the specified foreign source key.
        /// </summary>
        /// <param name="src">List of source records to expand.</param>
        /// <param name="ctx">Database context.</param>
        /// <param name="dstTableName">Destination table name.</param>
        /// <param name="srcKey">Selector for the source key.</param>
        /// <param name="dstKey">Selector for the destination key.</param>
        /// <returns>List of records with the new foreign key property named with the given destination table name.</returns>
        public static List<dynamic> LoadReferences(this List<dynamic> src,
            IDbContext ctx,
            string dstTableName,
            Func<dynamic, dynamic> srcKey,
            Func<dynamic, dynamic> dstKey)
        {
            var q = ctx.Sql($"select * from {dstTableName}").QueryMany<dynamic>()
                .ToDictionary(k => dstKey(k), v => v);

            foreach (var x in src.Cast<IDictionary<string, object>>())
            {
                var k = srcKey(x);

                dynamic v = null;
                if (q.TryGetValue(k, out v))
                {
                    x.Add(dstTableName, v);
                }
            }

            return src;
        }
开发者ID:devel0,项目名称:Lib0,代码行数:31,代码来源:Extensions.cs


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