public static T Id <T>(this DataServiceQuery <T> dataServiceQuery, long id) { Contract.Requires(0 < id); // IMPORTANT: Do NOT change to dataServiceQuery.FirstOrDefault(...) as FirstOrDefault(...) is not supported!!! return(dataServiceQuery.Where("Id == @0", id).FirstOrDefault()); }
public object GetPropertyValue(string entityName, object keyValue, string propertyName) { DataServiceQuery query = CreateQuery(entityName); var entityMetadataType = GetTypeDefinition(entityName); var primaryField = entityMetadataType.Key().First().Name; var q = query.Where(primaryField + " = @0", keyValue).Select(propertyName); return(q._First()); }
public static Tenant Id(this DataServiceQuery <Tenant> dataServiceQuery, Guid id) { Contract.Requires(default(Guid) != id); // IMPORTANT: Do NOT change to dataServiceQuery.FirstOrDefault(...) as FirstOrDefault(...) is not supported!!! // ReSharper disable ReplaceWithSingleCallToFirstOrDefault return(dataServiceQuery.Where(entity => entity.Id == id).FirstOrDefault()); // ReSharper restore ReplaceWithSingleCallToFirstOrDefault }
/// <summary> /// 在此页将要在 Frame 中显示时进行调用。 /// </summary> /// <param name="e">描述如何访问此页的事件数据。Parameter /// 属性通常用于配置页。</param> protected override void OnNavigatedTo(NavigationEventArgs e) { searchOptions = e.Parameter as List <string>; loadingProgressRing.IsActive = true; searchTitleKey = searchOptions[0].Trim(); if (searchOptions.Count == 4) { searchAuthorKey = searchOptions[1].Trim(); searchDescriptionKey = searchOptions[2].Trim(); searchCategoryKey = searchOptions[3]; } else { searchAuthorKey = searchDescriptionKey = searchCategoryKey = ""; } courseDsq = (DataServiceQuery <COURSE_AVAIL>)(from course_avail in ctx.COURSE_AVAIL select course_avail); if (!searchCategoryKey.Equals("Any Categories") && !searchCategoryKey.Equals("")) { courseDsq = (DataServiceQuery <COURSE_AVAIL>)courseDsq.Where(c => c.CATE_NAME.Equals(searchCategoryKey)); } if (!searchTitleKey.Equals("")) { courseDsq = (DataServiceQuery <COURSE_AVAIL>)courseDsq.Where(c => c.TITLE.Contains(searchTitleKey)); } if (!searchAuthorKey.Equals("")) { courseDsq = (DataServiceQuery <COURSE_AVAIL>)courseDsq.Where(c => c.TEACHER_NAME.Contains(searchAuthorKey)); } if (!searchDescriptionKey.Equals("")) { courseDsq = (DataServiceQuery <COURSE_AVAIL>)courseDsq.Where(c => c.INTRO.Contains(searchDescriptionKey)); } courseDsq.BeginExecute(OnSearchResultComplete, null); UserProfileBt.DataContext = Constants.User; }
private DataServiceQuery ExcludeDeletedObjects(DataServiceQuery query) { bool hasIsDeletedProperty = HasField(query.ElementType, "IsDeleted"); if (hasIsDeletedProperty) { var deletedFilter = new BinaryOperator("IsDeleted", false); { return(query.Where(deletedFilter)); } } return(query); }
public virtual TEntity Load(Expression <Func <TEntity, bool> > predicate, params Expression <Func <TEntity, object> >[] expanders) { DataServiceQuery <TEntity> query = Context.CreateQuery <TEntity>(EntitySetName); query = query.Expand(expanders); IQueryable <TEntity> queryable = query.Where(predicate); TEntity existing = query.SingleOrDefault(); if (existing != null) { Entity = existing; } return(Entity); }
public override ClaimsPrincipal Authenticate(string resourceName, ClaimsPrincipal incomingPrincipal) { if (incomingPrincipal != null && incomingPrincipal.Identity.IsAuthenticated) { string upn = incomingPrincipal.Identity.Name; var ds = GetAuthenticatedDirectoryDataService(incomingPrincipal); // One call only when using Expand DataServiceQuery <User> query = ds.users.Expand("memberOf"); User user = query.Where(it => (it.objectId == upn)).SingleOrDefault(); // There could be "Role" too, that's why we filter with OfType<> List <Group> groups = user.memberOf.OfType <Group>().Select(mo => (Group)mo).ToList(); var roleClaims = groups.Select(g => new Claim(ClaimTypes.Role, g.displayName, null, "CLAIMISSUER_GRAPH")); ((ClaimsIdentity)incomingPrincipal.Identity).AddClaims(roleClaims); } return(incomingPrincipal); }
public static DataServiceQuery <TEntity> Where2 <TEntity>(this DataServiceQuery <TEntity> query, Expression <Func <TEntity, bool> > criteria) { return((DataServiceQuery <TEntity>)query.Where(criteria)); }
public static async Task <TEntity> FirstOrDefaultAsync <TEntity>(this DataServiceQuery <TEntity> query, Expression <Func <TEntity, bool> > predicate) { var entities = await((DataServiceQuery <TEntity>)query.Where(predicate).Take(1)).ExecuteAsync(); return(entities.FirstOrDefault()); }
public static TSource FirstOrDefault <TSource>(this DataServiceQuery <TSource> dataServiceQuery, Expression <Func <TSource, bool> > predicate) { return(dataServiceQuery.Where(predicate).FirstOrDefault()); }
public DbReadOnlyRepository(DbUnitOfWork <TDbContext> unitOfWork, Func <TDbContext, DataServiceQuery <TEntity> > dbSetAccessor, bool useExtendedDataQuery) : base(() => dbSetAccessor(unitOfWork.Context), null, useExtendedDataQuery) { this.dbSetAccessor = dbSetAccessor; this.unitOfWork = unitOfWork; this.localCollection = new Lazy <DataServiceCollection <TEntity> >(() => new DataServiceCollection <TEntity>(DbSet.Where(x => false))); }