diff --git a/NeuroSpeech.EntityAccessControl/BaseEntityController.cs b/NeuroSpeech.EntityAccessControl/BaseEntityController.cs index 0a040d4..378f4f2 100644 --- a/NeuroSpeech.EntityAccessControl/BaseEntityController.cs +++ b/NeuroSpeech.EntityAccessControl/BaseEntityController.cs @@ -559,6 +559,8 @@ public async Task InvokeAsync( where T : class { var q = db.FilteredQuery(); + var type = db.GetType(); + options.Type = type; var result = await MethodParser.Instance.Parse(q, options); return Serialize(result); } diff --git a/NeuroSpeech.EntityAccessControl/Parser/LinqMethodOptions.cs b/NeuroSpeech.EntityAccessControl/Parser/LinqMethodOptions.cs index 22ec818..0cf7d90 100644 --- a/NeuroSpeech.EntityAccessControl/Parser/LinqMethodOptions.cs +++ b/NeuroSpeech.EntityAccessControl/Parser/LinqMethodOptions.cs @@ -13,5 +13,7 @@ public class LinqMethodOptions public Action? Trace { get; set; } public CancellationToken CancelToken { get; set; } + internal Type Type { get; set; } + } } diff --git a/NeuroSpeech.EntityAccessControl/Parser/MethodParser.cs b/NeuroSpeech.EntityAccessControl/Parser/MethodParser.cs index fbd0444..7d94964 100644 --- a/NeuroSpeech.EntityAccessControl/Parser/MethodParser.cs +++ b/NeuroSpeech.EntityAccessControl/Parser/MethodParser.cs @@ -4,6 +4,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Text.Json; using System.Threading.Tasks; @@ -26,25 +27,34 @@ private readonly ConcurrentDictionary cache public async Task Parse(IQueryable queryContext, LinqMethodOptions args) { - var d = await Parse(new CacheKeyBuilder(typeof(T), args.Methods)); + var d = await Parse(args); return await d(queryContext, args); } - public Task> Parse(CacheKeyBuilder methods) + private Task> Parse(LinqMethodOptions args) { + var methods = new CacheKeyBuilder(typeof(T), args.Methods); var key = methods.CacheKey; - return (Task>)cache.GetOrAdd(key, k => ParseQuery(methods.Methods)); + return (Task>)cache.GetOrAdd(key, k => ParseQuery(args, methods.Methods)); } - private Task> ParseQuery(List methods) + private Task> ParseQuery(LinqMethodOptions args, List methods) { + var list = new List {typeof(Queryable).Assembly, + typeof(Microsoft.EntityFrameworkCore.EF).Assembly, + typeof(QueryParser).Assembly, + typeof(RelationalQueryableExtensions).Assembly, + typeof(T).Assembly + }; + + if (!list.Contains(args.Type.Assembly)) + { + list.Add(args.Type.Assembly); + } + var options = ScriptOptions.Default - .AddReferences(typeof(Queryable).Assembly, - typeof(Microsoft.EntityFrameworkCore.EF).Assembly, - typeof(QueryParser).Assembly, - typeof(RelationalQueryableExtensions).Assembly, - typeof(T).Assembly) + .AddReferences(list) .WithOptimizationLevel(OptimizationLevel.Debug); var type = typeof(T);