本文整理汇总了C#中IQueryable类的典型用法代码示例。如果您正苦于以下问题:C# IQueryable类的具体用法?C# IQueryable怎么用?C# IQueryable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IQueryable类属于命名空间,在下文中一共展示了IQueryable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Country_Get_All
public void Country_Get_All()
{
//Arrange
data = new List<Country>() {
new Country() { Id = 1, Name = "US" },
new Country() { Id = 2, Name = "India" },
new Country() { Id = 3, Name = "Russia" }
}.AsQueryable();
mockContext = new Mock<IContext>();
mockSet = new Mock<IDbSet<Country>>();
mockSet.Setup(m => m.Provider).Returns(data.Provider);
mockSet.Setup(m => m.Expression).Returns(data.Expression);
mockSet.Setup(m => m.ElementType).Returns(data.ElementType);
mockSet.Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
mockContext.SetupGet(c => c.Countries).Returns(mockSet.Object);
_service = new CountryService(mockContext.Object);
//Act
IQueryable<Country> results = _service.GetAll() as IQueryable<Country>;
//Assert
Assert.IsNotNull(results);
Assert.AreEqual(3, results.ToList().Count);
}
开发者ID:DureSameen,项目名称:RoomReservation2,代码行数:31,代码来源:CountryServiceTest.cs
示例2: ApplyRolesFilter
/// <summary>
/// Applies the roles filter.
/// </summary>
/// <param name="query">The query.</param>
/// <param name="model">The model.</param>
/// <returns>Query with roles filter applied</returns>
private IQueryable<Models.User> ApplyRolesFilter(IQueryable<Models.User> query, GetUsersModel model)
{
if (model.FilterByRoles != null && model.FilterByRoles.Any(role => !string.IsNullOrWhiteSpace(role)))
{
var predicate = (model.FilterByRolesConnector == FilterConnector.Or)
? PredicateBuilder.False<Models.User>()
: PredicateBuilder.True<Models.User>();
foreach (var roleName in model.FilterByRoles)
{
if (!string.IsNullOrWhiteSpace(roleName))
{
Expression<Func<Models.User, bool>> whereClause = user => user.UserRoles.Any(userRole => userRole.Role.Name == roleName && !userRole.Role.IsDeleted);
if (model.FilterByRolesConnector == FilterConnector.Or)
{
predicate = PredicateBuilder.Or(predicate, whereClause);
}
else
{
predicate = PredicateBuilder.And(predicate, whereClause);
}
}
}
query = query.Where(predicate);
}
return query;
}
开发者ID:vivekmalikymca,项目名称:BetterCMS,代码行数:35,代码来源:UsersService.cs
示例3: BlogPosts
public static List<BlogPostVModel> BlogPosts(IQueryable<SeqPost> result)
{
List<BlogPostVModel> blogList = new List<BlogPostVModel>();
BlogPostVModel post;
if (result == null) return blogList;
foreach (SeqPost sp in result) {
post = new BlogPostVModel();
post.BlogPostId = sp.PostId;
post.Title = sp.Title;
post.Description = sp.Description;
post.ExtendedDescription = sp.ExtendedText;
post.Excerpt = sp.Excerpt;
post.CreateDate = sp.CreateDate;
post.Permalink = sp.Permalink;
foreach (SeqTag st in sp.SeqTags) {
TagVModel tvm = new TagVModel();
tvm.BlogId = st.BlogId;
tvm.TagId = st.TagId;
tvm.Name = st.Name;
post.Tags.Add(tvm);
}
blogList.Add(post);
}
return blogList;
}
开发者ID:ctsui,项目名称:Sequential,代码行数:25,代码来源:VModelFactory.cs
示例4: UpdatedPackages
public UpdatedPackages(
IQueryable<IPackage> installedPackages,
IPackageRepository aggregrateRepository)
{
this.installedPackages = installedPackages;
this.sourceRepository = aggregrateRepository;
}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:7,代码来源:UpdatedPackages.cs
示例5: GetQueryable
public override IQueryable GetQueryable(IQueryable source)
{
string selectedValue = DropDownList1.SelectedValue;
if (String.IsNullOrEmpty(selectedValue))
{
return source;
}
if (selectedValue == NullValueString)
{
return ApplyEqualityFilter(source, Column.Name, null);
}
IDictionary dict = new Hashtable();
Column.ExtractForeignKey(dict, selectedValue);
foreach (DictionaryEntry entry in dict)
{
string key = (string)entry.Key;
if (DefaultValues != null)
{
DefaultValues[key] = entry.Value;
}
source = ApplyEqualityFilter(source, Column.GetFilterExpression(key), entry.Value);
}
return source;
}
开发者ID:damy90,项目名称:Telerik-all,代码行数:26,代码来源:ForeignKey.ascx.cs
示例6: FilterDeviceList
/// <summary>
/// Filters the device list with the supplied filters
/// </summary>
/// <param name="list">Devices to filter</param>
/// <param name="filters">Filters to apply</param>
/// <returns>Set of devices that pass all the filters</returns>
public static IQueryable<dynamic> FilterDeviceList(
IQueryable<dynamic> list,
List<FilterInfo> filters)
{
if (list == null)
{
throw new ArgumentNullException("list");
}
if (filters == null)
{
return list;
}
list = list.Where(GetIsNotNull).AsQueryable();
foreach (var f in filters)
{
if ((f != null) && !string.IsNullOrEmpty(f.ColumnName))
{
list = FilterItems(list, f);
}
}
return list;
}
开发者ID:selam99,项目名称:azure-iot-remote-monitoring,代码行数:32,代码来源:FilterHelper.cs
示例7: BaseCollectionResult
/// <summary>
/// Initializes a new instance of the <see cref="BaseCollectionResult" /> class.
/// </summary>
/// <param name="query">The query that returns a collection of objects.</param>
/// <param name="edmType">The EDM type reference of the objects.</param>
/// <param name="context">The context where the action is executed.</param>
protected BaseCollectionResult(IQueryable query, IEdmTypeReference edmType, ApiContext context)
: base(edmType, context)
{
Ensure.NotNull(query, "query");
this.Query = query;
}
开发者ID:adestis-mh,项目名称:RESTier,代码行数:13,代码来源:BaseCollectionResult.cs
示例8: FilterCustomers
private static IQueryable<Customer> FilterCustomers(IQueryable<Customer> customers, Rule rule)
{
if (rule.field == "CustomerId")
{
int result;
if (!int.TryParse(rule.data, out result))
return customers;
return customers.Where(c => c.CustomerID == Convert.ToInt32(rule.data));
}
if (rule.field == "Name")
return from c in customers
where c.FirstName.Contains(rule.data) || c.LastName.Contains(rule.data)
select c;
if (rule.field == "Company")
return customers.Where(c => c.CompanyName.Contains(rule.data));
if (rule.field == "EmailAddress")
return customers.Where(c => c.EmailAddress.Contains(rule.data));
if (rule.field == "Last Modified")
{
DateTime result;
if (!DateTime.TryParse(rule.data, out result))
return customers;
if (result < new DateTime(1754, 1, 1)) // sql can't handle dates before 1-1-1753
return customers;
return customers.Where(c => c.ModifiedDate.Date == Convert.ToDateTime(rule.data).Date);
}
if (rule.field == "Telephone")
return customers.Where(c => c.Phone.Contains(rule.data));
return customers;
}
开发者ID:reharik,项目名称:MvcJqGrid,代码行数:31,代码来源:Repository.cs
示例9: CreateFilteredRequestTable
public static MvcHtmlString CreateFilteredRequestTable(this HtmlHelper helper, IQueryable<FilteredRequestRecord> filteredRequestRecords, Localizer T)
{
StringBuilder sb = new StringBuilder();
if (filteredRequestRecords == null || !filteredRequestRecords.Any())
{
sb.AppendLine(T("No requests are filtered yet.").Text);
}
else
{
sb.AppendLine("<table><tr>");
sb.AppendFormat("<th>{0}</th>", T("Request time"));
sb.AppendFormat("<th>{0}</th>", T("Url"));
sb.AppendFormat("<th>{0}</th>", T("User Host Address"));
sb.AppendFormat("<th>{0}</th>", T("User Agent"));
sb.AppendLine("</tr>");
foreach (FilteredRequestRecord filteredRequest in filteredRequestRecords.OrderByDescending(r => r.RequestTime))
{
sb.AppendLine("<tr>");
sb.AppendFormat("<td>{0}</td>", filteredRequest.RequestTime);
sb.AppendFormat("<td>{0}</td>", filteredRequest.Url);
sb.AppendFormat("<td>{0}</td>", filteredRequest.UserHostAddress);
sb.AppendFormat("<td>{0}</td>", filteredRequest.UserAgent);
sb.AppendLine("</tr>");
}
sb.AppendLine("</table>");
}
return new MvcHtmlString(sb.ToString());
}
开发者ID:rijkshuisstijl,项目名称:Rijkshuisstijl.UrlProtector,代码行数:30,代码来源:UrlProtectorHtmlHelper.cs
示例10: BuildLinqExpression
public override Expression BuildLinqExpression(IQueryable query, Expression expression, Expression item = null)
{
var leftExpression = this.LeftNode.BuildLinqExpression(query, expression, item);
var rightExpression = this.RightNode.BuildLinqExpression(query, expression, item);
// Nasty workaround to avoid comparison of Aggregate functions to true or false which breaks Entity framework
if (leftExpression.Type == typeof(bool) && rightExpression.Type == typeof(bool) && rightExpression is ConstantExpression)
{
if ((bool)(rightExpression as ConstantExpression).Value)
{
return leftExpression;
}
return Expression.Not(leftExpression);
}
if (rightExpression.Type == typeof(bool) && leftExpression.Type == typeof(bool)
&& leftExpression is ConstantExpression)
{
if ((bool)(leftExpression as ConstantExpression).Value)
{
return rightExpression;
}
return Expression.Not(rightExpression);
}
NormalizeTypes(ref leftExpression, ref rightExpression);
return ApplyEnsuringNullablesHaveValues(Expression.Equal, leftExpression, rightExpression);
}
开发者ID:calebjenkins,项目名称:LinqToQuerystring,代码行数:31,代码来源:EqualsNode.cs
示例11: PackageListViewModel
public PackageListViewModel(
IQueryable<Package> packages,
DateTime? indexTimestampUtc,
string searchTerm,
int totalCount,
int pageIndex,
int pageSize,
UrlHelper url,
string curatedFeed)
{
// TODO: Implement actual sorting
IEnumerable<ListPackageItemViewModel> items = packages.ToList().Select(pv => new ListPackageItemViewModel(pv));
PageIndex = pageIndex;
IndexTimestampUtc = indexTimestampUtc;
PageSize = pageSize;
TotalCount = totalCount;
SearchTerm = searchTerm;
int pageCount = (TotalCount + PageSize - 1) / PageSize;
var pager = new PreviousNextPagerViewModel<ListPackageItemViewModel>(
items,
PageIndex,
pageCount,
page => curatedFeed == null ?
url.PackageList(page, searchTerm) :
url.CuratedPackageList(page, searchTerm, curatedFeed)
);
Items = pager.Items;
FirstResultIndex = 1 + (PageIndex * PageSize);
LastResultIndex = FirstResultIndex + Items.Count() - 1;
Pager = pager;
}
开发者ID:hugoparedes,项目名称:NuGetGallery,代码行数:32,代码来源:PackageListViewModel.cs
示例12: MemberAccess
public static MemberAccessExpressionBuilderBase MemberAccess(IQueryable source, Type memberType, string memberName)
{
var builder = MemberAccess(source.ElementType, memberType, memberName);
builder.Options.LiftMemberAccessToNull = source.Provider.IsLinqToObjectsProvider();
return builder;
}
开发者ID:KevinDai,项目名称:Framework.Infrastructure,代码行数:7,代码来源:ExpressionBuilderFactory.cs
示例13: PackageListViewModel
public PackageListViewModel(IQueryable<Package> packages,
string searchTerm,
string sortOrder,
int totalCount,
int pageIndex,
int pageSize,
UrlHelper url,
bool includePrerelease)
{
// TODO: Implement actual sorting
IEnumerable<ListPackageItemViewModel> items;
using (MiniProfiler.Current.Step("Querying and mapping packages to list"))
{
items = packages.ToList()
.Select(pv => new ListPackageItemViewModel(pv, needAuthors: false));
}
PageIndex = pageIndex;
PageSize = pageSize;
TotalCount = totalCount;
SortOrder = sortOrder;
SearchTerm = searchTerm;
int pageCount = (TotalCount + PageSize - 1) / PageSize;
var pager = new PreviousNextPagerViewModel<ListPackageItemViewModel>(
items,
PageIndex,
pageCount,
page => url.PackageList(page, sortOrder, searchTerm, includePrerelease)
);
Items = pager.Items;
FirstResultIndex = 1 + (PageIndex * PageSize);
LastResultIndex = FirstResultIndex + Items.Count() - 1;
Pager = pager;
IncludePrerelease = includePrerelease ? "true" : null;
}
开发者ID:Redsandro,项目名称:chocolatey.org,代码行数:35,代码来源:PackageListViewModel.cs
示例14: ApplyFilter
public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
{
//If the Staff USI Isn't set, then no-op.
if (providerQueryOptions.StaffUSI <= 0)
return query;
//The only way a Staff member can be associated with a student at LEA is via the Staff Cohort tables. Only check that one table.
if (providerQueryOptions.LocalEducationAgencyId.HasUsableValue() && !providerQueryOptions.SchoolId.HasUsableValue())
{
var staffStudentCohorts = StaffStudentCohortRepository.GetAll();
IQueryable<StaffCohort> staffCohort = StaffCohortRepository.GetAll().Where(sc => sc.StaffUSI == providerQueryOptions.StaffUSI);
return query.Where(si => staffStudentCohorts
.SelectMany(ssc => staffCohort.Where(sc => ssc.StaffCohortId == sc.StaffCohortId).Select(sc => ssc))
.Any(ssc => ssc.StudentUSI == si.StudentUSI));
}
//At the school level, a staff member can be associated by Cohort or by Section. This view collapses the two.
var ssa = StaffStudentAssociationRepository.GetAll();
return query.Where(student => ssa.Any(ms => ms.StudentUSI == student.StudentUSI
&& ms.SchoolId == student.SchoolId
//This filters on school id, because if a teacher is a teacher at two schools,
//We need to filter on the Staff Section records only for the current school.
&& ms.SchoolId == providerQueryOptions.SchoolId.GetValueOrDefault()
&& ms.StaffUSI == providerQueryOptions.StaffUSI));
}
开发者ID:sybrix,项目名称:EdFi-App,代码行数:26,代码来源:StaffUSIFilter.cs
示例15: ApplySelectAndExpand
public IQueryable ApplySelectAndExpand(IQueryable queryable, HttpRequestMessage request )
{
var result = queryable;
var hasSelectOrExpand = false;
var map = request.RequestUri.ParseQueryString();
var selectQueryString = map["$select"];
if (!string.IsNullOrWhiteSpace(selectQueryString)) {
var selectClauses = selectQueryString.Split(',').Select(sc => sc.Replace('/', '.')).ToList();
var elementType = TypeFns.GetElementType(queryable.GetType());
var func = QueryBuilder.BuildSelectFunc(elementType, selectClauses);
result = func(result);
hasSelectOrExpand = true;
}
var expandsQueryString = map["$expand"];
if (!string.IsNullOrWhiteSpace(expandsQueryString)) {
if (!string.IsNullOrWhiteSpace(selectQueryString)) {
throw new Exception("Use of both 'expand' and 'select' in the same query is not currently supported");
}
expandsQueryString.Split(',').Select(s => s.Trim()).ToList().ForEach(expand => {
result = ((dynamic) result).Include(expand.Replace('/', '.'));
});
hasSelectOrExpand = true;
}
return hasSelectOrExpand ? result : null;
}
开发者ID:kangu,项目名称:Breeze,代码行数:29,代码来源:BreezeQueryableAttribute.cs
示例16: QueryLog
public void QueryLog(IQueryable linqQuery)
{
_querytype = QueryType.LINQ;
_linqQuery = linqQuery.Expression.ToString();
_StoreSQL = ToTraceString(linqQuery);
CreateLogEntry();
}
开发者ID:sridhar19091986,项目名称:pcapsctpspliter,代码行数:7,代码来源:Class1.cs
示例17: GetQueryable
public override IQueryable GetQueryable(IQueryable source)
{
string searchString = textBox.Text.Trim();
if (String.IsNullOrEmpty(searchString))
return source;
ConstantExpression searchFilter = Expression.Constant(searchString);
ParameterExpression param = Expression.Parameter(source.ElementType);
MemberExpression property = Expression.Property(param, this.Column.Name);
if (Nullable.GetUnderlyingType(property.Type) != null)
property = Expression.Property(property, "Value");
MethodInfo method = typeof(String).GetMethod("Contains", new[] { typeof(String) });
var containsMethodExp = Expression.Call(property, method, searchFilter);
var containsLambda = Expression.Lambda(containsMethodExp, param);
var resultExpression = Expression.Call(
typeof(Queryable),
"Where",
new Type[] { source.ElementType },
source.Expression,
Expression.Quote(containsLambda));
return source.Provider.CreateQuery(resultExpression);
}
开发者ID:sxmanderson,项目名称:Misc-projects-and-samples,代码行数:27,代码来源:SkillName.ascx.cs
示例18: AddNeededWhereClauses
private IQueryable<SubscriptionPost> AddNeededWhereClauses(string query,
IQueryable<SubscriptionPost> subscriptionPosts)
{
foreach (var whereClause in GetWhereClausesFromQuery(query))
{
switch (whereClause.PropertyName)
{
case PropertyName.Author:
subscriptionPosts = subscriptionPosts
.Where(x => x.Authors.Contains(whereClause.Text) == whereClause.MustContainText);
break;
case PropertyName.Content:
subscriptionPosts = subscriptionPosts
.Where(x => x.Content.Contains(whereClause.Text) == whereClause.MustContainText);
break;
case PropertyName.Categories:
subscriptionPosts = subscriptionPosts
.Where(x => x.Categories.Contains(whereClause.Text) == whereClause.MustContainText);
break;
case PropertyName.Feed:
subscriptionPosts = subscriptionPosts
.Where(x => x.Subscription.Title.Contains(whereClause.Text) == whereClause.MustContainText);
break;
case PropertyName.Title:
subscriptionPosts = subscriptionPosts
.Where(x => x.Title.Contains(whereClause.Text) == whereClause.MustContainText);
break;
}
}
return subscriptionPosts;
}
开发者ID:nakioman,项目名称:bralek,代码行数:31,代码来源:FeedItemsService.cs
示例19: GroupDescriptorExpressionBuilder
public GroupDescriptorExpressionBuilder(IQueryable queryable, GroupDescriptor groupDescriptor, GroupDescriptorExpressionBuilder childBuilder, IQueryable notPagedData)
: base(queryable)
{
this.groupDescriptor = groupDescriptor;
this.childBuilder = childBuilder;
this.notPagedData = notPagedData;
}
开发者ID:vialpando09,项目名称:RallyPortal2,代码行数:7,代码来源:GroupDescriptorExpressionBuilder.cs
示例20: ContributionsList
public IEnumerable<ContributionInfo> ContributionsList(IQueryable<Contribution> query)
{
var q2 = from c in query
let bd = c.BundleDetails.FirstOrDefault()
select new ContributionInfo
{
BundleId = bd == null ? 0 : bd.BundleHeaderId,
ContributionAmount = c.ContributionAmount,
ContributionDate = c.ContributionDate,
ContributionId = c.ContributionId,
ContributionType = c.ContributionType.Description,
ContributionTypeId = c.ContributionTypeId,
Fund = c.ContributionFund.FundName,
NonTaxDed =
c.ContributionTypeId == ContributionTypeCode.NonTaxDed ||
(c.ContributionFund.NonTaxDeductible ?? false),
StatusId = c.ContributionStatusId,
Status = c.ContributionStatus.Description,
Name = c.Person.Name,
PeopleId = c.PeopleId ?? 0,
Description = c.ContributionDesc,
CheckNo = c.CheckNo
};
return q2;
}
开发者ID:rossspoon,项目名称:bvcms,代码行数:25,代码来源:APIContributionSearchModel.cs
注:本文中的IQueryable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论