本文整理汇总了C#中Serenity.Data.SqlQuery.GetFirst方法的典型用法代码示例。如果您正苦于以下问题:C# SqlQuery.GetFirst方法的具体用法?C# SqlQuery.GetFirst怎么用?C# SqlQuery.GetFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serenity.Data.SqlQuery
的用法示例。
在下文中一共展示了SqlQuery.GetFirst方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessReplaceFields
internal static string ProcessReplaceFields(string s, Dictionary<string, Field> replaceFields, ISaveRequestHandler handler)
{
if (replaceFields == null)
return s;
var row = handler.Row;
// foreign / calculated fields might not be available yet in new row
// so load them from database
// TODO: if referenced foreign fields changed on update,
// values might be wrong in before update where we set filename
// so need to handle update in AfterSave just like create
if (handler.IsCreate &&
replaceFields.Values.Any(x => !x.IsTableField()))
{
var idField = (Field)(((IIdRow)handler.Row).IdField);
row = handler.Row.Clone();
var query = new SqlQuery()
.From(row);
foreach (var field in replaceFields.Values)
query.Select(field);
query.Where(idField == new ValueCriteria(idField.AsObject(row)));
query.GetFirst(handler.Connection);
}
foreach (var p in replaceFields)
{
var val = p.Value.AsObject(row);
string str;
var colon = p.Key.IndexOf(":");
if (colon >= 0)
str = String.Format("{0:" + p.Key.Substring(colon + 1, p.Key.Length - colon - 2) + "}", val);
else
str = Convert.ToString(val ?? "", CultureInfo.InvariantCulture);
str = StringHelper.SanitizeFilename(str).Replace('\\', '_').Replace("..", "_");
if (string.IsNullOrWhiteSpace(str))
str = "_";
while (str.EndsWith("."))
str = str.Substring(0, str.Length - 1) + "_";
s = s.Replace(p.Key, str);
}
while (s.IndexOf("//") > 0)
s = s.Replace("//", "/_/");
return s;
}