public static IQueryable SelectManyInterpolated(this IQueryable source, FormattableString collectionSelector, FormattableString resultSelector) { var collectionSelectorStr = ParseFormattableString(collectionSelector, out var collectionSelectorArgs); var resultSelectorStr = ParseFormattableString(resultSelector, out var resultSelectorArgs); return(DynamicQueryableExtensions.SelectMany(source, collectionSelectorStr, collectionSelectorArgs, resultSelectorStr, resultSelectorArgs)); }
private static async Task InitUsersAsync( IServiceScope serviceScope, IEnumerable <TestUser> testUsers = null ) { var uowProvider = serviceScope.ServiceProvider.GetRequiredService <IUowProvider>(); var userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(); if ((testUsers != null) && (!DynamicQueryableExtensions.Any(userManager.Users))) { foreach (var inMemoryUser in testUsers) { var identityUser = new ApplicationUser(inMemoryUser.Username); userManager.CreateAsync(identityUser, inMemoryUser.Password).Wait(); userManager.AddToRoleAsync(identityUser, SystemRoleTypes.SuperAdmin.ToString()).Wait(); using (var uow = uowProvider.CreateUnitOfWork()) { var userRepository = uow.GetRepository <UserProfile, string>(); await userRepository.AddAsync(new UserProfile { Id = identityUser.Id, FirstName = "SuperAdmin", MiddleName = "SuperAdmin", LastName = "SuperAdmin", Email = "*****@*****.**" } ); await uow.SaveChangesAsync(); } } } }
/// <summary> /// 排序 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="ordering">排序字符串,如:OrderBy("id desc,name ase")</param> /// <param name="values"></param> /// <returns></returns> public static IQueryable <T> OrderBy <T>(this IQueryable <T> query, string ordering, params object[] values) { if (query == null) { throw new ArgumentNullException("query"); } return(DynamicQueryableExtensions.OrderBy(query, ordering, values)); }
/// <summary> /// 查询条件(IQueryable) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="ivm"></param> /// <returns></returns> public static IQueryable <T> QueryWhere <T>(IQueryable <T> query, QueryDataInputVM ivm) { //条件 if (!string.IsNullOrWhiteSpace(ivm.wheres)) { var whereItems = JArray.Parse(ivm.wheres); foreach (var item in whereItems) { //关系符 var relation = item["relation"].ToStringOrEmpty(); string rel = DicSqlRelation[relation]; //字段 var field = item["field"].ToStringOrEmpty(); //值 var value = item["value"]; //值引号 var vqm = "\""; switch (relation) { case "Equal": case "NotEqual": case "LessThan": case "GreaterThan": case "LessThanOrEqual": case "GreaterThanOrEqual": { string val = vqm + value.ToStringOrEmpty() + vqm; string iwhere = string.Format(rel, field, val); query = DynamicQueryableExtensions.Where(query, iwhere); } break; case "Contains": case "StartsWith": case "EndsWith": { query = DynamicQueryableExtensions.Where(query, field + "." + relation + "(@0)", value.ToStringOrEmpty()); } break; case "BetweenAnd": if (value.Count() == 2) { var v1 = vqm + value[0].ToString() + vqm; var v2 = vqm + value[1].ToString() + vqm; var iwhere = string.Format(rel, field, v1, v2); query = DynamicQueryableExtensions.Where(query, iwhere); } break; } } } return(query); }
public List <TEntity> FindList(IQueryable <TEntity> query, DataBase.Pagination pag) { pag.Total = query.Count(); string OrderBys = DataBase.OrderByJoin(pag.SortName, pag.SortOrder, false); query = DynamicQueryableExtensions.OrderBy(query, OrderBys); query = query.Skip((pag.PageNumber - 1) * pag.PageSize).Take(pag.PageSize); return(query.ToList()); }
public static IOrderedQueryable <TSource> OrderBy <TSource>(this IQueryable <TSource> source, string ordering = null, params object[] args) where TSource : class { if (string.IsNullOrEmpty(ordering)) { source = OrderByAttributes(source); } else { source = DynamicQueryableExtensions.OrderBy(source, ordering, args); } return((IOrderedQueryable <TSource>)source); }
public List <TEntity> FindList(Expression <Func <TEntity, bool> > pWhere, DataBase.Pagination pag) { var query = dbSet.AsNoTracking().Where(pWhere); pag.Total = query.Count(); string OrderBys = DataBase.OrderByJoin(pag.SortName, pag.SortOrder, false); query = DynamicQueryableExtensions.OrderBy(query, OrderBys); query = query.Skip((pag.PageNumber - 1) * pag.PageSize).Take(pag.PageSize); return(query.ToList()); }
private List <Kişi> FiltreOrder(List <Kişi> kisiList, string order, bool desc) { var quarable = kisiList.AsQueryable(); if (!desc) { return(DynamicQueryableExtensions.OrderBy(quarable, order).ToList()); } else { return(DynamicQueryableExtensions.OrderBy(quarable, order + " desc").ToList()); } }
private static async Task InitIdentityServerAsync( IServiceScope serviceScope, IEnumerable <Client> initialClients = null, IEnumerable <ApiResource> initialApiResources = null, IEnumerable <IdentityResource> initialIdentityResources = null ) { serviceScope.ServiceProvider.GetRequiredService <CoreManageDbContext>().Database.Migrate(); var grantContext = serviceScope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>(); try { await grantContext.Database.MigrateAsync(); } catch (System.NotImplementedException) { grantContext.Database.Migrate(); } var configContext = serviceScope.ServiceProvider.GetRequiredService <ConfigurationDbContext>(); try { await configContext.Database.MigrateAsync(); } catch (System.NotImplementedException) { configContext.Database.Migrate(); } // intitial clients if ((initialClients != null) && (!DynamicQueryableExtensions.Any(configContext.Clients))) { foreach (var client in initialClients) { var c = client.ToEntity(); configContext.Clients.Add(c); } await configContext.SaveChangesAsync(); } // intitial apiResources if ((initialApiResources != null) && (!DynamicQueryableExtensions.Any(configContext.ApiResources))) { foreach (var scope in initialApiResources) { var s = scope.ToEntity(); configContext.ApiResources.Add(s); } await configContext.SaveChangesAsync(); } // intitial identityResources if ((initialIdentityResources != null) && (!DynamicQueryableExtensions.Any(configContext.IdentityResources))) { foreach (var scope in initialIdentityResources) { var s = scope.ToEntity(); configContext.IdentityResources.Add(s); } await configContext.SaveChangesAsync(); } }
private static async Task InitRolesAsync(IServiceScope serviceScope) { var roleManager = serviceScope.ServiceProvider.GetRequiredService <RoleManager <ApplicationRole> >(); if (!DynamicQueryableExtensions.Any(roleManager.Roles)) { await roleManager.CreateAsync(new ApplicationRole(SystemRoles.SuperAdmin, (int)SystemRoleTypes.SuperAdmin)); await roleManager.CreateAsync(new ApplicationRole(SystemRoles.GroupAdmin, (int)SystemRoleTypes.SuperAdmin)); await roleManager.CreateAsync(new ApplicationRole(SystemRoles.TenantAdmin, (int)SystemRoleTypes.GroupAdmin)); await roleManager.CreateAsync(new ApplicationRole(SystemRoles.DashboardAdmin, (int)SystemRoleTypes.TenantAdmin)); // (Module/ApiClient) } }
public void OrderBy_Dynamic_Exceptions() { //Arrange var testList = User.GenerateSampleModels(100, allowNullableProfiles: true); var qry = testList.AsQueryable(); //Act Assert.Throws <ParseException>(() => qry.OrderBy("Bad=3")); Assert.Throws <ParseException>(() => qry.Where("Id=123")); Assert.Throws <ArgumentNullException>(() => DynamicQueryableExtensions.OrderBy(null, "Id")); Assert.Throws <ArgumentNullException>(() => qry.OrderBy(null)); Assert.Throws <ArgumentException>(() => qry.OrderBy("")); Assert.Throws <ArgumentException>(() => qry.OrderBy(" ")); }
private static IQueryable <TSource> OrderByAttributes <TSource>(IQueryable <TSource> source) where TSource : class { var sortProperty = typeof(TSource) .GetProperties() .Where(p => p.GetCustomAttribute(typeof(SortAttribute)) != null) .Select(p => new { PropertyName = p.Name, SortAttribute = (SortAttribute)p.GetCustomAttribute(typeof(SortAttribute)) }) .OrderBy(p => p.SortAttribute.Order) .Select(p => $"{p.PropertyName} {p.SortAttribute.Direction}"); return(DynamicQueryableExtensions.OrderBy(source, string.Join(",", sortProperty))); }
public PagedResultDto <TEntityDto> ApplyPagination(IQueryable <IEntidadeBase> set, PagedAndSortedResultRequestDto input) { var result = set.PageBy(input).ToList(); var secondResult = result.AsQueryable().Select(x => ObjectMapper .Map(x, Activator.CreateInstance <TEntityDto>())) .ToList(); return(new PagedResultDto <TEntityDto> { TotalCount = DynamicQueryableExtensions.Count(set), Items = secondResult }); }
public void Select_Dynamic_Exceptions() { //Arrange var testList = User.GenerateSampleModels(100, allowNullableProfiles: true); var qry = testList.AsQueryable(); //Act Assert.Throws <ParseException>(() => qry.Select("Bad")); Assert.Throws <ParseException>(() => qry.Select("Id, UserName")); Assert.Throws <ParseException>(() => qry.Select("new Id, UserName")); Assert.Throws <ParseException>(() => qry.Select("new (Id, UserName")); Assert.Throws <ParseException>(() => qry.Select("new (Id, UserName, Bad)")); Assert.Throws <ArgumentNullException>(() => DynamicQueryableExtensions.Select(null, "Id")); Assert.Throws <ArgumentNullException>(() => qry.Select(null)); Assert.Throws <ArgumentException>(() => qry.Select("")); Assert.Throws <ArgumentException>(() => qry.Select(" ")); }
public void Select_Dynamic_Exceptions() { //Arrange var testList = User.GenerateSampleModels(100, allowNullableProfiles: true); var qry = testList.AsQueryable(); //Act Assert.Throws <ParseException>(() => qry.Select("Bad")); Assert.Throws <ParseException>(() => qry.Select("Id, UserName")); Assert.Throws <ParseException>(() => qry.Select("new Id, UserName")); Assert.Throws <ParseException>(() => qry.Select("new (Id, UserName")); Assert.Throws <ParseException>(() => qry.Select("new (Id, UserName, Bad)")); Check.ThatCode(() => qry.Select <User>("new User(it.Bad as Bad)")).Throws <ParseException>().WithMessage("No property or field 'Bad' exists in type 'User'"); Assert.Throws <ArgumentNullException>(() => DynamicQueryableExtensions.Select(null, "Id")); Assert.Throws <ArgumentNullException>(() => qry.Select(null)); Assert.Throws <ArgumentException>(() => qry.Select("")); Assert.Throws <ArgumentException>(() => qry.Select(" ")); }
public static IQueryable <T> DyOrderBy <T>(this IQueryable <T> query, string ordering, params object[] values) { return(!string.IsNullOrEmpty(ordering) ? DynamicQueryableExtensions.OrderBy(query, ordering, values) : query); }
public IActionResult LoadPlaceData() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) try { StringValues val = this.Request.Form["draw"]; string draw = ((IEnumerable <string>)(object) this.Request.Form["draw"]).FirstOrDefault(); string text = ((IEnumerable <string>)(object) this.Request.Form["start"]).FirstOrDefault(); string text2 = ((IEnumerable <string>)(object) this.Request.Form["length"]).FirstOrDefault(); string text3 = ((IEnumerable <string>)(object) this.Request.Form["columns[" + ((IEnumerable <string>)(object) this.Request.Form["order[0][column]"]).FirstOrDefault() + "][name]"]).FirstOrDefault(); string text4 = ((IEnumerable <string>)(object) this.Request.Form["order[0][dir]"]).FirstOrDefault(); string searchValue = ((IEnumerable <string>)(object) this.Request.Form["search[value]"]).FirstOrDefault(); int count = (text2 != null) ? Convert.ToInt32(text2) : 0; int count2 = (text != null) ? Convert.ToInt32(text) : 0; int num = 0; IQueryable <Place> queryable = _placeService.GetPlaceQueryable(); if (base.CurrentUser.Role != UserRole.SuperAdmin) { int companyId = base.CurrentUser.CompanyId; queryable = from w in queryable where w.CompanyId == companyId select w; } if (!string.IsNullOrEmpty(text3) || !string.IsNullOrEmpty(text4)) { queryable = DynamicQueryableExtensions.OrderBy <Place>(queryable, text3 + " " + text4, Array.Empty <object>()); } if (!string.IsNullOrEmpty(searchValue)) { queryable = from m in queryable where m.Name.Contains(searchValue) select m; } num = queryable.Count(); var items = queryable.Skip(count2).Take(count).ToList(); // { "data": "id", "name": "Id", "autoWidth": true }, // { "data": "companyName", "name": "CompanyName", "autoWidth": true }, // { "data": "name", "name": "Name", "autoWidth": true }, // { "data": "address", "name": "Address", "autoWidth": true }, // { "data": "latitude", "name": "Latitude", "autoWidth": true }, // { "data": "longitude", "name": "Longitude", "autoWidth": true }, // { "data": "guest", "name": "Guest", "autoWidth": true }, // { "data": "createdDate", "name": "CreatedDate", "autoWidth": true }, var data = items.Select(a => new { a.Id, CompanyName = a.Company.Name, a.Name, a.Address, a.Latitude, a.Longitude, a.CreatedDate , Guest = string.Equals(a.Guest, "Evet", StringComparison.InvariantCultureIgnoreCase) ? "Evet" : "Hayır" , }).ToList(); return(this.Json((object)new { draw = draw, recordsFiltered = num, recordsTotal = num, data = data })); } catch (Exception) { int num2 = 5; throw; } }
public static dynamic?LastOrDefaultInterpolated(this IQueryable source, ParsingConfig config, FormattableString predicate) { var predicateStr = ParseFormattableString(predicate, out var args); return(DynamicQueryableExtensions.LastOrDefault(source, config, predicateStr, args)); }
public IActionResult LoadCompanyData() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) try { StringValues val = this.Request.Form["draw"]; string draw = ((IEnumerable <string>)(object) this.Request.Form["draw"]).FirstOrDefault(); string text = ((IEnumerable <string>)(object) this.Request.Form["start"]).FirstOrDefault(); string text2 = ((IEnumerable <string>)(object) this.Request.Form["length"]).FirstOrDefault(); string text3 = ((IEnumerable <string>)(object) this.Request.Form["columns[" + ((IEnumerable <string>)(object) this.Request.Form["order[0][column]"]).FirstOrDefault() + "][name]"]).FirstOrDefault(); string text4 = ((IEnumerable <string>)(object) this.Request.Form["order[0][dir]"]).FirstOrDefault(); string searchValue = ((IEnumerable <string>)(object) this.Request.Form["search[value]"]).FirstOrDefault(); int count = (text2 != null) ? Convert.ToInt32(text2) : 0; int count2 = (text != null) ? Convert.ToInt32(text) : 0; int num = 0; IQueryable <Company> queryable = _companyService.GetCompanyQueryable(); if (!string.IsNullOrEmpty(text3) || !string.IsNullOrEmpty(text4)) { queryable = DynamicQueryableExtensions.OrderBy <Company>(queryable, text3 + " " + text4, Array.Empty <object>()); } if (!string.IsNullOrEmpty(searchValue)) { queryable = from m in queryable where m.Name.Contains(searchValue) select m; } num = queryable.Count(); //List<Company> data = queryable.Skip(count2).Take(count).ToList(); var items = queryable.Skip(count2).Take(count).ToList(); var data = items.Select(a => new { a.Id, a.Name, a.Address, a.CreatedDate , Demo = string.Equals(a.Demo, "Evet", StringComparison.InvariantCultureIgnoreCase) ? "Evet" : "Hayır" , CompanyTypeName = _companyTypes.ContainsKey(a.CompanyTypeId) ? _companyTypes[a.CompanyTypeId] : "Diğer" }).ToList(); return(this.Json((object)new { draw = draw, recordsFiltered = num, recordsTotal = num, data = data })); } catch (Exception) { int num2 = 5; throw; } }
/// <summary> /// 查询条件 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="param"></param> /// <returns></returns> public static IQueryable <T> QueryWhere <T>(IQueryable <T> query, QueryDataVM.GetParams param) { //条件 if (!string.IsNullOrWhiteSpace(param.wheres)) { var whereItems = JArray.Parse(param.wheres); foreach (var item in whereItems) { //关系符 var relation = item["relation"].ToStringOrEmpty(); string rel = DicSqlRelation[relation]; //字段 var field = item["field"].ToStringOrEmpty(); //值 var value = item["value"]; //值引号 var vqm = "\""; switch (relation) { case "Equal": case "NotEqual": case "LessThan": case "GreaterThan": case "LessThanOrEqual": case "GreaterThanOrEqual": { string val = vqm + value.ToStringOrEmpty() + vqm; string iwhere = string.Format(rel, field, val); query = DynamicQueryableExtensions.Where(query, iwhere); } break; case "Contains": case "StartsWith": case "EndsWith": { string iwhere = string.Format(rel, value.ToStringOrEmpty()); query = query.Where(x => EF.Functions.Like(x.GetType().GetProperty(field).GetValue(x, null).ToString(), iwhere)); } break; case "BetweenAnd": if (value.Count() == 2) { var v1 = vqm + value[0].ToString() + vqm; var v2 = vqm + value[1].ToString() + vqm; var iwhere = string.Format(rel, field, v1, v2); query = DynamicQueryableExtensions.Where(query, iwhere); } break; case "In": { var list = new List <string>(); int len = value.Count(); for (int i = 0; i < len; i++) { list.Add(value[i].ToString()); } query = query.Where(x => list.Contains(x.GetType().GetProperty(field).GetValue(x, null).ToString())); } break; case "NotIn": { var list = new List <string>(); int len = value.Count(); for (int i = 0; i < len; i++) { list.Add(value[i].ToString()); } query = query.Where(x => !list.Contains(x.GetType().GetProperty(field).GetValue(x, null).ToString())); } break; } } } return(query); }
public static IQueryable SelectManyInterpolated(this IQueryable source, ParsingConfig config, Type resultType, FormattableString selector) { var selectorStr = ParseFormattableString(selector, out var args); return(DynamicQueryableExtensions.SelectMany(source, config, resultType, selectorStr, args)); }
public static IQueryable <TSource> WhereInterpolated <TSource>(this IQueryable <TSource> source, FormattableString predicate) { var predicateStr = ParseFormattableString(predicate, out var args); return(DynamicQueryableExtensions.Where(source, predicateStr, args)); }
public static IQueryable <TResult> SelectManyInterpolated <TResult>(this IQueryable source, FormattableString selector) { var selectorStr = ParseFormattableString(selector, out var args); return(DynamicQueryableExtensions.SelectMany <TResult>(source, selectorStr, args)); }
public static IOrderedQueryable <TSource> OrderByInterpolated <TSource>(this IQueryable <TSource> source, ParsingConfig config, FormattableString ordering, IComparer comparer) { var orderingStr = ParseFormattableString(ordering, out var args); return(DynamicQueryableExtensions.OrderBy(source, config, orderingStr, comparer, args)); }
public static IOrderedQueryable ThenByInterpolated(this IOrderedQueryable source, FormattableString ordering, IComparer comparer) { var orderingStr = ParseFormattableString(ordering, out var args); return(DynamicQueryableExtensions.ThenBy(source, orderingStr, comparer, args)); }
public static IOrderedQueryable <TSource> ThenByInterpolated <TSource>(this IOrderedQueryable <TSource> source, FormattableString ordering) { var orderingStr = ParseFormattableString(ordering, out var args); return(DynamicQueryableExtensions.ThenBy(source, orderingStr, args)); }
//[PublicAPI] public static double AverageInterpolated(this IQueryable source, ParsingConfig config, FormattableString predicate) { var predicateStr = ParseFormattableString(predicate, out var args); return(DynamicQueryableExtensions.Average(source, config, predicateStr, args)); }
public static dynamic SingleInterpolated(this IQueryable source, FormattableString predicate) { var predicateStr = ParseFormattableString(predicate, out var args); return(DynamicQueryableExtensions.Single(source, predicateStr, args)); }