Skip to content

Commit 326817c

Browse files
authored
Merge pull request #80 from WeihanLi/dev
10.0.0 preview 6
2 parents a47d46c + a77f93b commit 326817c

File tree

9 files changed

+66
-104
lines changed

9 files changed

+66
-104
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<LangVersion>preview</LangVersion>
77
<ImplicitUsings>enable</ImplicitUsings>
88
<Nullable>enable</Nullable>
9-
<CommonVersion>1.0.77</CommonVersion>
10-
<EFVersion>10.0.0-preview.3.25171.6</EFVersion>
9+
<CommonVersion>1.0.80</CommonVersion>
10+
<EFVersion>10.0.0-preview.6.25358.103</EFVersion>
1111

1212
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1313
<EmbedUntrackedSources>true</EmbedUntrackedSources>

WeihanLi.EntityFramework.sln

Lines changed: 0 additions & 91 deletions
This file was deleted.

WeihanLi.EntityFramework.slnx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Solution>
2+
<Folder Name="/samples/">
3+
<Project Path="samples/WeihanLi.EntityFramework.Sample/WeihanLi.EntityFramework.Sample.csproj" />
4+
</Folder>
5+
<Folder Name="/src/">
6+
<Project Path="src/WeihanLi.EntityFramework.SourceGenerator/WeihanLi.EntityFramework.SourceGenerator.csproj" />
7+
<Project Path="src/WeihanLi.EntityFramework/WeihanLi.EntityFramework.csproj" />
8+
</Folder>
9+
<Folder Name="/test/">
10+
<Project Path="test/WeihanLi.EntityFramework.Test/WeihanLi.EntityFramework.Test.csproj" />
11+
</Folder>
12+
</Solution>

build/build.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
var noPush = CommandLineParser.BooleanVal("noPush", args);
55
var branchName = EnvHelper.Val("BUILD_SOURCEBRANCHNAME", "local");
66

7-
var solutionPath = "./WeihanLi.EntityFramework.sln";
7+
var solutionPath = "./WeihanLi.EntityFramework.slnx";
88
string[] srcProjects = [
99
"./src/WeihanLi.EntityFramework/WeihanLi.EntityFramework.csproj"
1010
];

samples/WeihanLi.EntityFramework.Sample/Program.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public static class Program
2121
public static async Task Main(string[] args)
2222
{
2323
// SoftDeleteTest();
24-
// RepositoryTest();
24+
RepositoryTest();
2525
// AutoAuditTest();
2626

27-
await DbContextInterceptorSamples.RunAsync();
27+
// await DbContextInterceptorSamples.RunAsync();
2828

2929
Console.WriteLine("completed");
3030
Console.ReadLine();
@@ -212,7 +212,7 @@ private static void RepositoryTest()
212212
var conn = db.Database.GetDbConnection();
213213
try
214214
{
215-
conn.Execute($@"TRUNCATE TABLE {tableName}");
215+
conn.Execute($"TRUNCATE TABLE {tableName}");
216216
}
217217
catch
218218
{
@@ -241,6 +241,14 @@ private static void RepositoryTest()
241241
var abc = db.TestEntities.AsNoTracking().ToArray();
242242
Console.WriteLine($"{string.Join(Environment.NewLine, abc.Select(_ => _.ToJson()))}");
243243

244+
var entities = repo.Query(q => q.IgnoreQueryFilters(["not-null"]))
245+
.ToArray();
246+
Console.WriteLine(entities.Length);
247+
248+
entities = repo.Query(q => q.IgnoreQueryFilters())
249+
.ToArray();
250+
Console.WriteLine(entities.Length);
251+
244252
var data = repo.Query(q => q.WithPredictIf(f => f.Id > 0, false)).ToArray();
245253
Console.WriteLine(JsonSerializer.Serialize(data));
246254

samples/WeihanLi.EntityFramework.Sample/TestDbContext.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ public TestDbContext(DbContextOptions<TestDbContext> options) : base(options)
1111
{
1212
}
1313

14+
protected override void OnModelCreating(ModelBuilder modelBuilder)
15+
{
16+
base.OnModelCreating(modelBuilder);
17+
modelBuilder.Entity<TestEntity>()
18+
// .HasQueryFilter("one-month-ago", t => t.CreatedAt > DateTime.Now.AddMonths(-1))
19+
.HasQueryFilter("valid-id", t => t.Id > 0)
20+
.HasQueryFilter("not-null", t => t.Extra != null)
21+
;
22+
}
23+
1424
public DbSet<TestEntity> TestEntities { get; set; } = null!;
1525
}
1626

src/WeihanLi.EntityFramework.SourceGenerator/WeihanLi.EntityFramework.SourceGenerator.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all" />
24-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
23+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" PrivateAssets="all" />
24+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0" PrivateAssets="all" />
2525
</ItemGroup>
2626

2727
</Project>

src/WeihanLi.EntityFramework/EFRepositoryQueryBuilder.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using Microsoft.EntityFrameworkCore;
22
using Microsoft.EntityFrameworkCore.Query;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
63
using System.Linq.Expressions;
74
using WeihanLi.Common;
85

@@ -56,6 +53,28 @@ public EFRepositoryQueryBuilder<TEntity> IgnoreQueryFilters(bool ignoreQueryFilt
5653
return this;
5754
}
5855

56+
private readonly HashSet<string> _queryFiltersToIgnore = new();
57+
58+
public EFRepositoryQueryBuilder<TEntity> IgnoreQueryFilters(IReadOnlyCollection<string> queryFilters, bool ignoreQueryFilters = true)
59+
{
60+
ArgumentNullException.ThrowIfNull(queryFilters);
61+
if (ignoreQueryFilters)
62+
{
63+
foreach (var queryFilter in queryFilters)
64+
{
65+
_queryFiltersToIgnore.Add(queryFilter);
66+
}
67+
}
68+
else
69+
{
70+
foreach (var queryFilter in queryFilters)
71+
{
72+
_queryFiltersToIgnore.Remove(queryFilter);
73+
}
74+
}
75+
return this;
76+
}
77+
5978
private int _count;
6079

6180
public EFRepositoryQueryBuilder<TEntity> WithCount(int count)
@@ -83,6 +102,10 @@ public IQueryable<TEntity> Build()
83102
{
84103
query = query.IgnoreQueryFilters();
85104
}
105+
else if (_queryFiltersToIgnore.Count > 0)
106+
{
107+
query = query.IgnoreQueryFilters(_queryFiltersToIgnore);
108+
}
86109
if (_whereExpression.Count > 0)
87110
{
88111
foreach (var expression in _whereExpression)

test/WeihanLi.EntityFramework.Test/WeihanLi.EntityFramework.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(EFVersion)" />
1414
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EFVersion)" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
16-
<PackageReference Include="xunit.v3" Version="2.0.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
16+
<PackageReference Include="xunit.v3" Version="3.0.0" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

0 commit comments

Comments
 (0)