本文整理汇总了C#中SimpleQuery.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# SimpleQuery.ToList方法的具体用法?C# SimpleQuery.ToList怎么用?C# SimpleQuery.ToList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleQuery
的用法示例。
在下文中一共展示了SimpleQuery.ToList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResult
public virtual async Task<Paged<Entities.Url>> GetResult(Filter.Simple.Data.Filter filter, int? accountId = null)
{
filter.Resource = "Urls";
DataStrategy strategy = Database.Open();
var query = new SimpleQuery(strategy, filter.Resource);
var limit = _limit.Apply(filter);
var skip = _skip.Apply(filter);
dynamic accounts;
query = query.Join(ObjectReference.FromString("Accounts"), JoinType.Inner, out accounts)
.On(accounts.Id == new ObjectReference("AccountId", ObjectReference.FromString("Urls")))
.Select(
new ObjectReference("Id", ObjectReference.FromString("Urls")),
new ObjectReference("Address", ObjectReference.FromString("Urls")),
new ObjectReference("Id", ObjectReference.FromString("Accounts")).As("Account_Id"))
.Skip(_skip.Apply(filter))
.Take(_limit.Apply(filter));
if (accountId.HasValue)
{
var leftOperand = new ObjectReference("AccountId", ObjectReference.FromString("Urls"));
query.Where(new SimpleExpression(leftOperand, accountId, SimpleExpressionType.Equal));
}
if (filter.HasOrdering)
{
query = query.OrderBy(_order.Apply(filter), OrderByDirection.Ascending);
}
var data = await query.ToList<dynamic>();
var entities = AutoMapper.MapDynamic<Entities.Url>(data).ToList();
if (!entities.Any())
{
return null;
}
return new Paged<Entities.Url>
{
Limit = limit,
Skip = skip,
Data = entities
};
}
示例2: FormatQuery
private static object FormatQuery(SimpleQuery simpleQuery)
{
bool hasCount = simpleQuery.Clauses.OfType<WithCountClause>().Any();
var list = simpleQuery.ToList();
if (list.Count == 0)
return "No matching records.";
var firstRow = list.FirstOrDefault() as IDictionary<string, object>;
if (firstRow == null) throw new InvalidOperationException();
var table = new DataTable();
foreach (var kvp in firstRow)
{
table.Columns.Add(kvp.Key);
}
foreach (var row in list.Cast<IDictionary<string, object>>())
{
table.Rows.Add(row.Values.ToArray());
}
return table.DefaultView;
}