diff --git a/Directory.Build.props b/Directory.Build.props
index b96a009..3038510 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -6,8 +6,8 @@
preview
enable
enable
- 1.0.77
- 10.0.0-preview.3.25171.6
+ 1.0.80
+ 10.0.0-preview.6.25358.103
true
true
diff --git a/WeihanLi.EntityFramework.sln b/WeihanLi.EntityFramework.sln
deleted file mode 100644
index adfa9ac..0000000
--- a/WeihanLi.EntityFramework.sln
+++ /dev/null
@@ -1,91 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.29409.12
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeihanLi.EntityFramework", "src\WeihanLi.EntityFramework\WeihanLi.EntityFramework.csproj", "{0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{40B7673F-5ACD-42E4-AE04-6C3AEEBC8546}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{46AED92E-94FC-409A-9CFB-C9CD4E59717D}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeihanLi.EntityFramework.Sample", "samples\WeihanLi.EntityFramework.Sample\WeihanLi.EntityFramework.Sample.csproj", "{0E013C55-6D52-4B68-B188-460B97DB1E48}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeihanLi.EntityFramework.Test", "test\WeihanLi.EntityFramework.Test\WeihanLi.EntityFramework.Test.csproj", "{9DF6D464-63A7-487C-9763-4A212ADDFC4B}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A1756F80-F25E-4ADC-A079-048FFCA5DBA6}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeihanLi.EntityFramework.SourceGenerator", "src\WeihanLi.EntityFramework.SourceGenerator\WeihanLi.EntityFramework.SourceGenerator.csproj", "{010A98BE-1871-4E6F-8129-7A1C44C73423}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Debug|x64 = Debug|x64
- Debug|x86 = Debug|x86
- Release|Any CPU = Release|Any CPU
- Release|x64 = Release|x64
- Release|x86 = Release|x86
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Debug|x64.ActiveCfg = Debug|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Debug|x64.Build.0 = Debug|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Debug|x86.ActiveCfg = Debug|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Debug|x86.Build.0 = Debug|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Release|Any CPU.Build.0 = Release|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Release|x64.ActiveCfg = Release|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Release|x64.Build.0 = Release|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Release|x86.ActiveCfg = Release|Any CPU
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A}.Release|x86.Build.0 = Release|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Debug|x64.ActiveCfg = Debug|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Debug|x64.Build.0 = Debug|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Debug|x86.ActiveCfg = Debug|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Debug|x86.Build.0 = Debug|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Release|Any CPU.Build.0 = Release|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Release|x64.ActiveCfg = Release|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Release|x64.Build.0 = Release|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Release|x86.ActiveCfg = Release|Any CPU
- {0E013C55-6D52-4B68-B188-460B97DB1E48}.Release|x86.Build.0 = Release|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Debug|x64.ActiveCfg = Debug|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Debug|x64.Build.0 = Debug|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Debug|x86.ActiveCfg = Debug|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Debug|x86.Build.0 = Debug|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Release|Any CPU.Build.0 = Release|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Release|x64.ActiveCfg = Release|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Release|x64.Build.0 = Release|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Release|x86.ActiveCfg = Release|Any CPU
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Release|x86.Build.0 = Release|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|x64.ActiveCfg = Debug|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|x64.Build.0 = Debug|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|x86.ActiveCfg = Debug|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|x86.Build.0 = Debug|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|Any CPU.Build.0 = Release|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|x64.ActiveCfg = Release|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|x64.Build.0 = Release|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|x86.ActiveCfg = Release|Any CPU
- {010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|x86.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(NestedProjects) = preSolution
- {0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A} = {40B7673F-5ACD-42E4-AE04-6C3AEEBC8546}
- {0E013C55-6D52-4B68-B188-460B97DB1E48} = {46AED92E-94FC-409A-9CFB-C9CD4E59717D}
- {9DF6D464-63A7-487C-9763-4A212ADDFC4B} = {A1756F80-F25E-4ADC-A079-048FFCA5DBA6}
- {010A98BE-1871-4E6F-8129-7A1C44C73423} = {40B7673F-5ACD-42E4-AE04-6C3AEEBC8546}
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {201A8B4F-A16D-44B7-BB29-F9B9CFC2A467}
- EndGlobalSection
-EndGlobal
diff --git a/WeihanLi.EntityFramework.slnx b/WeihanLi.EntityFramework.slnx
new file mode 100644
index 0000000..43a0a82
--- /dev/null
+++ b/WeihanLi.EntityFramework.slnx
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/build.cs b/build/build.cs
index a54aab1..e0fa3d9 100644
--- a/build/build.cs
+++ b/build/build.cs
@@ -4,7 +4,7 @@
var noPush = CommandLineParser.BooleanVal("noPush", args);
var branchName = EnvHelper.Val("BUILD_SOURCEBRANCHNAME", "local");
-var solutionPath = "./WeihanLi.EntityFramework.sln";
+var solutionPath = "./WeihanLi.EntityFramework.slnx";
string[] srcProjects = [
"./src/WeihanLi.EntityFramework/WeihanLi.EntityFramework.csproj"
];
diff --git a/samples/WeihanLi.EntityFramework.Sample/Program.cs b/samples/WeihanLi.EntityFramework.Sample/Program.cs
index f879aed..117e3cf 100644
--- a/samples/WeihanLi.EntityFramework.Sample/Program.cs
+++ b/samples/WeihanLi.EntityFramework.Sample/Program.cs
@@ -21,10 +21,10 @@ public static class Program
public static async Task Main(string[] args)
{
// SoftDeleteTest();
- // RepositoryTest();
+ RepositoryTest();
// AutoAuditTest();
- await DbContextInterceptorSamples.RunAsync();
+ // await DbContextInterceptorSamples.RunAsync();
Console.WriteLine("completed");
Console.ReadLine();
@@ -212,7 +212,7 @@ private static void RepositoryTest()
var conn = db.Database.GetDbConnection();
try
{
- conn.Execute($@"TRUNCATE TABLE {tableName}");
+ conn.Execute($"TRUNCATE TABLE {tableName}");
}
catch
{
@@ -241,6 +241,14 @@ private static void RepositoryTest()
var abc = db.TestEntities.AsNoTracking().ToArray();
Console.WriteLine($"{string.Join(Environment.NewLine, abc.Select(_ => _.ToJson()))}");
+ var entities = repo.Query(q => q.IgnoreQueryFilters(["not-null"]))
+ .ToArray();
+ Console.WriteLine(entities.Length);
+
+ entities = repo.Query(q => q.IgnoreQueryFilters())
+ .ToArray();
+ Console.WriteLine(entities.Length);
+
var data = repo.Query(q => q.WithPredictIf(f => f.Id > 0, false)).ToArray();
Console.WriteLine(JsonSerializer.Serialize(data));
diff --git a/samples/WeihanLi.EntityFramework.Sample/TestDbContext.cs b/samples/WeihanLi.EntityFramework.Sample/TestDbContext.cs
index 9b4457d..a7e0335 100644
--- a/samples/WeihanLi.EntityFramework.Sample/TestDbContext.cs
+++ b/samples/WeihanLi.EntityFramework.Sample/TestDbContext.cs
@@ -11,6 +11,16 @@ public TestDbContext(DbContextOptions options) : base(options)
{
}
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ base.OnModelCreating(modelBuilder);
+ modelBuilder.Entity()
+ // .HasQueryFilter("one-month-ago", t => t.CreatedAt > DateTime.Now.AddMonths(-1))
+ .HasQueryFilter("valid-id", t => t.Id > 0)
+ .HasQueryFilter("not-null", t => t.Extra != null)
+ ;
+ }
+
public DbSet TestEntities { get; set; } = null!;
}
diff --git a/src/WeihanLi.EntityFramework.SourceGenerator/WeihanLi.EntityFramework.SourceGenerator.csproj b/src/WeihanLi.EntityFramework.SourceGenerator/WeihanLi.EntityFramework.SourceGenerator.csproj
index 86b9662..c3ecf63 100644
--- a/src/WeihanLi.EntityFramework.SourceGenerator/WeihanLi.EntityFramework.SourceGenerator.csproj
+++ b/src/WeihanLi.EntityFramework.SourceGenerator/WeihanLi.EntityFramework.SourceGenerator.csproj
@@ -20,8 +20,8 @@
-
-
+
+
diff --git a/src/WeihanLi.EntityFramework/EFRepositoryQueryBuilder.cs b/src/WeihanLi.EntityFramework/EFRepositoryQueryBuilder.cs
index b08e00f..8a5b434 100644
--- a/src/WeihanLi.EntityFramework/EFRepositoryQueryBuilder.cs
+++ b/src/WeihanLi.EntityFramework/EFRepositoryQueryBuilder.cs
@@ -1,8 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
-using System;
-using System.Collections.Generic;
-using System.Linq;
using System.Linq.Expressions;
using WeihanLi.Common;
@@ -56,6 +53,28 @@ public EFRepositoryQueryBuilder IgnoreQueryFilters(bool ignoreQueryFilt
return this;
}
+ private readonly HashSet _queryFiltersToIgnore = new();
+
+ public EFRepositoryQueryBuilder IgnoreQueryFilters(IReadOnlyCollection queryFilters, bool ignoreQueryFilters = true)
+ {
+ ArgumentNullException.ThrowIfNull(queryFilters);
+ if (ignoreQueryFilters)
+ {
+ foreach (var queryFilter in queryFilters)
+ {
+ _queryFiltersToIgnore.Add(queryFilter);
+ }
+ }
+ else
+ {
+ foreach (var queryFilter in queryFilters)
+ {
+ _queryFiltersToIgnore.Remove(queryFilter);
+ }
+ }
+ return this;
+ }
+
private int _count;
public EFRepositoryQueryBuilder WithCount(int count)
@@ -83,6 +102,10 @@ public IQueryable Build()
{
query = query.IgnoreQueryFilters();
}
+ else if (_queryFiltersToIgnore.Count > 0)
+ {
+ query = query.IgnoreQueryFilters(_queryFiltersToIgnore);
+ }
if (_whereExpression.Count > 0)
{
foreach (var expression in _whereExpression)
diff --git a/test/WeihanLi.EntityFramework.Test/WeihanLi.EntityFramework.Test.csproj b/test/WeihanLi.EntityFramework.Test/WeihanLi.EntityFramework.Test.csproj
index 737d3c4..e400c7f 100644
--- a/test/WeihanLi.EntityFramework.Test/WeihanLi.EntityFramework.Test.csproj
+++ b/test/WeihanLi.EntityFramework.Test/WeihanLi.EntityFramework.Test.csproj
@@ -12,8 +12,8 @@
-
-
+
+