本文整理匯總了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);
}
}