/// <summary> /// Gets the LINQ expression filter automatically applied to queries for this entity type. /// </summary> /// <param name="entityType"> The entity type to get the query filter for. </param> /// <returns> The LINQ expression filter factory. </returns> public static LambdaExpression TryGetQueryFilterFromFactory([NotNull] this IEntityType entityType) { Check.NotNull(entityType, nameof(entityType)); var factory = entityType[CoreAnnotationNames.QueryFilter] as Func <LambdaExpression>; if (factory != null) { var lambda = factory(); if (entityType is EntityType) { var dbSetAccessRewriter = new DbSetAccessRewritingExpressionVisitor(entityType.ClrType); var annotation = entityType.GetAnnotation(CoreAnnotationNames.QueryFilter); ((Annotation)annotation).Value = dbSetAccessRewriter.Visit(lambda); } return(lambda); } return(null); }
/// <summary> /// Creates a new instance of <see cref="QueryFilterRewritingConvention" />. /// </summary> /// <param name="dependencies">Parameter object containing dependencies for this convention.</param> public QueryFilterRewritingConvention(ProviderConventionSetBuilderDependencies dependencies) { Dependencies = dependencies; DbSetAccessRewriter = new DbSetAccessRewritingExpressionVisitor(dependencies.ContextType); }