本文整理汇总了C#中Serenity.Data.SqlQuery.SubQuery方法的典型用法代码示例。如果您正苦于以下问题:C# SqlQuery.SubQuery方法的具体用法?C# SqlQuery.SubQuery怎么用?C# SqlQuery.SubQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serenity.Data.SqlQuery
的用法示例。
在下文中一共展示了SqlQuery.SubQuery方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SubQueryCanBeUsedAsCriteriaUsingVar
public void SubQueryCanBeUsedAsCriteriaUsingVar()
{
var query = new SqlQuery()
.From("ParentTable")
.Select("ParentColumn");
query.Where(new Criteria(query.SubQuery()
.From("SubTable")
.Take(1)
.Select("SubColumn")) >= 1);
Assert.Equal(
TestSqlHelper.Normalize(
"SELECT ParentColumn FROM ParentTable WHERE " +
"((SELECT TOP 1 SubColumn FROM SubTable) >= @p1)"),
TestSqlHelper.Normalize(
query.ToString()));
}
示例2: SubQuerySharesParameters
public void SubQuerySharesParameters()
{
var query = new SqlQuery();
Assert.Equal(0, query.ParamCount);
var sub = query.SubQuery();
sub.AddParam("@px1", "value");
Assert.Equal(1, query.ParamCount);
Assert.Equal((string)query.Params["@px1"], "value");
}
示例3: OnPrepareQuery
public void OnPrepareQuery(IListRequestHandler handler, SqlQuery query)
{
if (ReferenceEquals(null, Target) ||
handler.Request.EqualityFilter == null ||
!attr.HandleEqualityFilter)
return;
object value;
if (handler.Request.EqualityFilter.TryGetValue(Target.PropertyName, out value) ||
handler.Request.EqualityFilter.TryGetValue(Target.Name, out value))
{
if (value == null || value as string == "")
return;
var values = new List<object>();
if (!(value is string) && value is IEnumerable)
{
foreach (var val in (IEnumerable)value)
values.Add(itemKeyField.ConvertValue(val, CultureInfo.InvariantCulture));
}
else
{
values.Add(itemKeyField.ConvertValue(value, CultureInfo.InvariantCulture));
}
if (values.Count > 0)
{
var ls = new Alias(itemKeyField.Fields.TableName, "__ls");
query.Where(Criteria.Exists(
query.SubQuery()
.From(ls)
.Select("1")
.Where(
new Criteria(ls[thisKeyField]) == new Criteria((Field)((IIdRow)handler.Row).IdField) &
new Criteria(ls[itemKeyField]).In(values))
.ToString()));
}
handler.IgnoreEqualityFilter(Target.PropertyName);
handler.IgnoreEqualityFilter(Target.Name);
}
}