public void Get_departments_with_filtered_inlude_with_filter_on_child_include() { ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>(); ICollection <DepartmentModel> list = Task.Run ( () => repository.GetItemsAsync <DepartmentModel, Department> ( d => d.Courses.Count > 0, null, null, new FilteredIncludeExpression[] { new FilteredIncludeExpression { Include = LinqHelpers.ToSelector <DepartmentModel, ICollection <CourseModel> >(i => i.Courses), FilteredIncludes = new FilteredIncludeExpression[] { new FilteredIncludeExpression { Include = LinqHelpers.ToSelector <CourseModel, ICollection <CourseAssignmentModel> >(i => i.Assignments), Filter = LinqHelpers.ToFilter <CourseAssignmentModel>(e => e.CourseID == -1) } } } } ) ).Result; Assert.True(list.First().Courses.Count > 0); Assert.True(list.First().Courses.First().Assignments.Count == 0); }
protected override Expression VisitMethodCall(MethodCallExpression methodCall) { if (methodCall.Method.MetadataToken == GetMethod.MetadataToken && Equals(methodCall.Method.Module, GetMethod.Module)) { object value; Throw <ODataCompileException> .If( !LinqHelpers.TryGetValue(methodCall.Arguments[0], LinqHelpers.GetValueOptions.All, out value), () => string.Format( "Unable to extract value for parameter '{0}' of {1}. Ensure that the value for the parameter can be statically determined", methodCall.Method.GetParameters()[0].Name, methodCall.Method ) ); var propertyName = (string)value; Throw <ODataCompileException> .If( string.IsNullOrWhiteSpace(propertyName), () => string.Format( "'{0}' value for {1} must not be null or whitespace", methodCall.Method.GetParameters()[0].Name, methodCall.Method ) ); var property = EntityPropertyInfo.For(name: propertyName, type: methodCall.Method.GetGenericArguments()[0]); return(Expression.Property(this.Visit(methodCall.Object), property)); } return(base.VisitMethodCall(methodCall)); }
private static Func <T, object> CreatePropertySelector <T>(string column, IEnumerable <string>?extraAllowedColumns) { var parameter = Expression.Parameter(typeof(T), "x"); var selector = Expression.PropertyOrField(parameter, column); LinqHelpers.CheckTargetColumn(column, extraAllowedColumns, selector); var cast = Expression.Convert(selector, typeof(object)); return((Func <T, object>)Expression.Lambda(cast, parameter).Compile()); }
private Expression Build(Expression leftExpression) { if (leftExpression.Type.IsList()) { return(leftExpression.GetConcatCall(Right.Build())); } else if (leftExpression.Type == typeof(string)) { return(LinqHelpers.GetStringConcatCall(leftExpression, Right.Build())); } else { throw new ArgumentException(nameof(leftExpression)); } }
private static MethodCallExpression Apply(string methodName, Expression source, Expression argument = null) { var result = Expression.Call( type: typeof(Queryable), methodName: methodName, typeArguments: methodName == "Select" || methodName.StartsWith("OrderBy", StringComparison.Ordinal) ? source.Type.GetGenericArguments(typeof(IQueryable <>)) .Concat(new[] { ((LambdaExpression)LinqHelpers.UnQuote(argument)).ReturnType }) .ToArray() : source.Type.GetGenericArguments(typeof(IQueryable <>)), arguments: argument != null ? new[] { source, argument } : new[] { source } ); return(result); }
private static ContentURI GetCalcDocStylesheetURI(ContentURI docToCalcURI) { ContentURI stylesheetURI = new ContentURI(); ContentURI calcDocURI = LinqHelpers.GetLinkedViewIsSelectedAddIn(docToCalcURI); if (calcDocURI == null) { calcDocURI = LinqHelpers.GetLinkedViewIsDefaultAddIn( docToCalcURI.URIDataManager.LinkedView); } if (calcDocURI != null) { stylesheetURI = LinqHelpers.GetContentURIListIsMainStylesheet( calcDocURI.URIDataManager.Resource); } return(stylesheetURI); }
public void Get_instuctors_with_filtered_inlude_conditionally_select_reference_with_invalid_condition() { ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>(); ICollection <InstructorModel> list = Task.Run ( () => repository.GetItemsAsync <InstructorModel, Instructor> ( i => i.OfficeAssignment != null, null, null, new FilteredIncludeExpression[] { new FilteredIncludeExpression { Include = LinqHelpers.ToSelector <InstructorModel, OfficeAssignmentModel>(i => i.OfficeAssignment), Filter = LinqHelpers.ToFilter <OfficeAssignmentModel>(oa => oa.Location.StartsWith("*")) } } ) ).Result; Assert.Null(list.First().OfficeAssignment); }
public void Get_students_with_filtered_inlude_with_filter() { ISchoolRepository repository = serviceProvider.GetRequiredService <ISchoolRepository>(); ICollection <StudentModel> list = Task.Run ( () => repository.GetItemsAsync <StudentModel, Student> ( s => s.Enrollments.Count > 0, null, null, new FilteredIncludeExpression[] { new FilteredIncludeExpression { Include = LinqHelpers.ToSelector <StudentModel, ICollection <EnrollmentModel> >(i => i.Enrollments), Filter = LinqHelpers.ToFilter <EnrollmentModel>(e => e.EnrollmentID == -1) } } ) ).Result; Assert.True(list.First().Enrollments.Count == 0); }
protected override Expression Build(Expression left, Expression right) { if (left.Type == typeof(string) || right.Type == typeof(string)) { return(base.Build ( LinqHelpers.GetStringCompareCall(left.SetNullType(typeof(string)), right.SetNullType(typeof(string))), Expression.Constant(0) )); } if (left.Type.ToNullableUnderlyingType() == typeof(Guid) || right.Type.ToNullableUnderlyingType() == typeof(Guid)) { return(base.Build ( LinqHelpers.GetGuidCopareCall(left.SetNullType(typeof(Guid)), right.SetNullType(typeof(Guid))), Expression.Constant(0) )); } return(base.Build(left, right)); }
public Expression Build() => LinqHelpers.GetMaxDateTimOffsetField();
public Expression Build() => LinqHelpers.GetNowDateTimOffsetProperty();