本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}