From 97bbc003fe7459fe908e132c180d38ab27604c0d Mon Sep 17 00:00:00 2001 From: Koen Bekkenutte <2912652+kbekkenutte@users.noreply.github.com> Date: Mon, 15 Nov 2021 20:34:36 +0800 Subject: [PATCH 1/4] Added minimal docs on the projectable attribute --- .../ProjectableAttribute.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/EntityFrameworkCore.Projectables.Abstractions/ProjectableAttribute.cs b/src/EntityFrameworkCore.Projectables.Abstractions/ProjectableAttribute.cs index dd4a368..14800e6 100644 --- a/src/EntityFrameworkCore.Projectables.Abstractions/ProjectableAttribute.cs +++ b/src/EntityFrameworkCore.Projectables.Abstractions/ProjectableAttribute.cs @@ -6,9 +6,15 @@ using System.Threading.Tasks; namespace EntityFrameworkCore.Projectables { + /// + /// Mark this method or property as a Projectable + /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = true, AllowMultiple = false)] public sealed class ProjectableAttribute : Attribute { + /// + /// Get or set how null-conditional operators are handeled + /// public NullConditionalRewriteSupport NullConditionalRewriteSupport { get; set; } } } From ac338aa3a000c3f809c42725a40426043b562e23 Mon Sep 17 00:00:00 2001 From: Koen Bekkenutte <2912652+kbekkenutte@users.noreply.github.com> Date: Mon, 15 Nov 2021 20:44:47 +0800 Subject: [PATCH 2/4] Added additional code docs --- .../Extensions/DbContextOptionsExtensions.cs | 6 ++++++ .../Extensions/ExpressionExtensions.cs | 3 +++ .../Extensions/QueryableExtensions.cs | 3 +++ .../Infrastructure/CompatibilityMode.cs | 8 ++++++++ .../Infrastructure/ProjectableOptionsBuilder.cs | 3 +++ 5 files changed, 23 insertions(+) diff --git a/src/EntityFrameworkCore.Projectables/Extensions/DbContextOptionsExtensions.cs b/src/EntityFrameworkCore.Projectables/Extensions/DbContextOptionsExtensions.cs index 9eb5984..88057d5 100644 --- a/src/EntityFrameworkCore.Projectables/Extensions/DbContextOptionsExtensions.cs +++ b/src/EntityFrameworkCore.Projectables/Extensions/DbContextOptionsExtensions.cs @@ -13,10 +13,16 @@ namespace Microsoft.EntityFrameworkCore { public static class DbContextOptionsExtensions { + /// + /// Use projectables within the queries. Any call to a Projectable property/method will automatically be translated to the underlying expression tree instead + /// public static DbContextOptionsBuilder UseProjectables(this DbContextOptionsBuilder optionsBuilder, Action? configure = null) where TContext : DbContext => (DbContextOptionsBuilder)UseProjectables((DbContextOptionsBuilder)optionsBuilder, configure); + /// + /// Use projectables within the queries. Any call to a Projectable property/method will automatically be translated to the underlying expression tree instead + /// public static DbContextOptionsBuilder UseProjectables(this DbContextOptionsBuilder optionsBuilder, Action? configure = null) { var extension = optionsBuilder.Options.FindExtension() ?? new ProjectionOptionsExtension(); diff --git a/src/EntityFrameworkCore.Projectables/Extensions/ExpressionExtensions.cs b/src/EntityFrameworkCore.Projectables/Extensions/ExpressionExtensions.cs index 0d91dca..36878a2 100644 --- a/src/EntityFrameworkCore.Projectables/Extensions/ExpressionExtensions.cs +++ b/src/EntityFrameworkCore.Projectables/Extensions/ExpressionExtensions.cs @@ -16,6 +16,9 @@ namespace EntityFrameworkCore.Projectables.Extensions public static Expression ExpandQuaryables(this Expression expression) => ExpandProjectables(expression); + /// + /// Replaces all calls to properties and methods that are marked with the Projectable attribute with their respective expression tree + /// public static Expression ExpandProjectables(this Expression expression) => _projectableExpressionReplacer.Visit(expression); } diff --git a/src/EntityFrameworkCore.Projectables/Extensions/QueryableExtensions.cs b/src/EntityFrameworkCore.Projectables/Extensions/QueryableExtensions.cs index 710dad0..4be751b 100644 --- a/src/EntityFrameworkCore.Projectables/Extensions/QueryableExtensions.cs +++ b/src/EntityFrameworkCore.Projectables/Extensions/QueryableExtensions.cs @@ -13,6 +13,9 @@ namespace EntityFrameworkCore.Projectables.Extensions public static IQueryable ExpandQuaryables(this IQueryable query) => ExpandProjectables(query); + /// + /// Replaces all calls to properties and methods that are marked with the Projectable attribute with their respective expression tree + /// public static IQueryable ExpandProjectables(this IQueryable query) => query.Provider.CreateQuery(query.Expression.ExpandProjectables()); } diff --git a/src/EntityFrameworkCore.Projectables/Infrastructure/CompatibilityMode.cs b/src/EntityFrameworkCore.Projectables/Infrastructure/CompatibilityMode.cs index 54217a0..4e95022 100644 --- a/src/EntityFrameworkCore.Projectables/Infrastructure/CompatibilityMode.cs +++ b/src/EntityFrameworkCore.Projectables/Infrastructure/CompatibilityMode.cs @@ -8,7 +8,15 @@ namespace EntityFrameworkCore.Projectables.Infrastructure { public enum CompatibilityMode { + /// + /// 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 + /// Full, + /// + /// Projectables are expanded in the query preprocessor and afterwards cached. + /// This is the default compatibility mode. + /// Limited } } diff --git a/src/EntityFrameworkCore.Projectables/Infrastructure/ProjectableOptionsBuilder.cs b/src/EntityFrameworkCore.Projectables/Infrastructure/ProjectableOptionsBuilder.cs index d7a3668..697a6e5 100644 --- a/src/EntityFrameworkCore.Projectables/Infrastructure/ProjectableOptionsBuilder.cs +++ b/src/EntityFrameworkCore.Projectables/Infrastructure/ProjectableOptionsBuilder.cs @@ -18,6 +18,9 @@ namespace EntityFrameworkCore.Projectables.Infrastructure _optionsBuilder = optionsBuilder ?? throw new ArgumentNullException(nameof(optionsBuilder)); } + /// + /// Change the default CompatibilityMode + /// public ProjectableOptionsBuilder CompatibilityMode(CompatibilityMode mode) => WithOption(x => x.WithCompatibilityMode(mode)); From 0450ed08603f9f65632f45606d90713cb8d47519 Mon Sep 17 00:00:00 2001 From: Koen Bekkenutte <2912652+kbekkenutte@users.noreply.github.com> Date: Fri, 26 Nov 2021 00:04:53 +0800 Subject: [PATCH 3/4] Updated Projectable attribute docs --- .../ProjectableAttribute.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/EntityFrameworkCore.Projectables.Abstractions/ProjectableAttribute.cs b/src/EntityFrameworkCore.Projectables.Abstractions/ProjectableAttribute.cs index 14800e6..248076a 100644 --- a/src/EntityFrameworkCore.Projectables.Abstractions/ProjectableAttribute.cs +++ b/src/EntityFrameworkCore.Projectables.Abstractions/ProjectableAttribute.cs @@ -7,7 +7,8 @@ using System.Threading.Tasks; namespace EntityFrameworkCore.Projectables { /// - /// Mark this method or property as a Projectable + /// Declares this property or method to be Projectable. + /// A companion Expression tree will be generated /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = true, AllowMultiple = false)] public sealed class ProjectableAttribute : Attribute From 7aa5eeb5728abc38b4f5e1479b491581c80daf32 Mon Sep 17 00:00:00 2001 From: Koen Bekkenutte <2912652+kbekkenutte@users.noreply.github.com> Date: Fri, 26 Nov 2021 00:05:20 +0800 Subject: [PATCH 4/4] Removed unused folder reference --- .../EntityFrameworkCore.Projectables.Generator.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/EntityFrameworkCore.Projectables.Generator/EntityFrameworkCore.Projectables.Generator.csproj b/src/EntityFrameworkCore.Projectables.Generator/EntityFrameworkCore.Projectables.Generator.csproj index 3349b07..80111b0 100644 --- a/src/EntityFrameworkCore.Projectables.Generator/EntityFrameworkCore.Projectables.Generator.csproj +++ b/src/EntityFrameworkCore.Projectables.Generator/EntityFrameworkCore.Projectables.Generator.csproj @@ -15,8 +15,4 @@ - - - -