Merge pull request #8 from koenbeuk/missing-docs

Added minimal docs on the projectable attribute
This commit is contained in:
Koen
2021-11-26 19:54:31 +08:00
committed by GitHub
7 changed files with 30 additions and 4 deletions
@@ -6,9 +6,16 @@ using System.Threading.Tasks;
namespace EntityFrameworkCore.Projectables
{
/// <summary>
/// Declares this property or method to be Projectable.
/// A companion Expression tree will be generated
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
public sealed class ProjectableAttribute : Attribute
{
/// <summary>
/// Get or set how null-conditional operators are handeled
/// </summary>
public NullConditionalRewriteSupport NullConditionalRewriteSupport { get; set; }
}
}
@@ -15,8 +15,4 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Folder Include="Internal\" />
</ItemGroup>
</Project>
@@ -13,10 +13,16 @@ namespace Microsoft.EntityFrameworkCore
{
public static class DbContextOptionsExtensions
{
/// <summary>
/// Use projectables within the queries. Any call to a Projectable property/method will automatically be translated to the underlying expression tree instead
/// </summary>
public static DbContextOptionsBuilder<TContext> UseProjectables<TContext>(this DbContextOptionsBuilder<TContext> optionsBuilder, Action<ProjectableOptionsBuilder>? configure = null)
where TContext : DbContext
=> (DbContextOptionsBuilder<TContext>)UseProjectables((DbContextOptionsBuilder)optionsBuilder, configure);
/// <summary>
/// Use projectables within the queries. Any call to a Projectable property/method will automatically be translated to the underlying expression tree instead
/// </summary>
public static DbContextOptionsBuilder UseProjectables(this DbContextOptionsBuilder optionsBuilder, Action<ProjectableOptionsBuilder>? configure = null)
{
var extension = optionsBuilder.Options.FindExtension<ProjectionOptionsExtension>() ?? new ProjectionOptionsExtension();
@@ -16,6 +16,9 @@ namespace EntityFrameworkCore.Projectables.Extensions
public static Expression ExpandQuaryables(this Expression expression)
=> ExpandProjectables(expression);
/// <summary>
/// Replaces all calls to properties and methods that are marked with the <C>Projectable</C> attribute with their respective expression tree
/// </summary>
public static Expression ExpandProjectables(this Expression expression)
=> _projectableExpressionReplacer.Visit(expression);
}
@@ -13,6 +13,9 @@ namespace EntityFrameworkCore.Projectables.Extensions
public static IQueryable<TModel> ExpandQuaryables<TModel>(this IQueryable<TModel> query)
=> ExpandProjectables(query);
/// <summary>
/// Replaces all calls to properties and methods that are marked with the <C>Projectable</C> attribute with their respective expression tree
/// </summary>
public static IQueryable<TModel> ExpandProjectables<TModel>(this IQueryable<TModel> query)
=> query.Provider.CreateQuery<TModel>(query.Expression.ExpandProjectables());
}
@@ -8,7 +8,15 @@ namespace EntityFrameworkCore.Projectables.Infrastructure
{
public enum CompatibilityMode
{
/// <summary>
/// Projectables are expanded on each individual query invocation.
/// This mode can be used when you wan't to pass scoped services to your Projectable methods
/// </summary>
Full,
/// <summary>
/// Projectables are expanded in the query preprocessor and afterwards cached.
/// This is the default compatibility mode.
/// </summary>
Limited
}
}
@@ -18,6 +18,9 @@ namespace EntityFrameworkCore.Projectables.Infrastructure
_optionsBuilder = optionsBuilder ?? throw new ArgumentNullException(nameof(optionsBuilder));
}
/// <summary>
/// Change the default CompatibilityMode
/// </summary>
public ProjectableOptionsBuilder CompatibilityMode(CompatibilityMode mode)
=> WithOption(x => x.WithCompatibilityMode(mode));