Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CommonVersion>1.0.77</CommonVersion>
<EFVersion>10.0.0-preview.3.25171.6</EFVersion>
<CommonVersion>1.0.80</CommonVersion>
<EFVersion>10.0.0-preview.6.25358.103</EFVersion>

<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down
91 changes: 0 additions & 91 deletions WeihanLi.EntityFramework.sln

This file was deleted.

12 changes: 12 additions & 0 deletions WeihanLi.EntityFramework.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Solution>
<Folder Name="/samples/">
<Project Path="samples/WeihanLi.EntityFramework.Sample/WeihanLi.EntityFramework.Sample.csproj" />
</Folder>
<Folder Name="/src/">
<Project Path="src/WeihanLi.EntityFramework.SourceGenerator/WeihanLi.EntityFramework.SourceGenerator.csproj" />
<Project Path="src/WeihanLi.EntityFramework/WeihanLi.EntityFramework.csproj" />
</Folder>
<Folder Name="/test/">
<Project Path="test/WeihanLi.EntityFramework.Test/WeihanLi.EntityFramework.Test.csproj" />
</Folder>
</Solution>
2 changes: 1 addition & 1 deletion build/build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];
Expand Down
14 changes: 11 additions & 3 deletions samples/WeihanLi.EntityFramework.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

public static class Program
{
public static async Task Main(string[] args)

Check warning on line 21 in samples/WeihanLi.EntityFramework.Sample/Program.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 21 in samples/WeihanLi.EntityFramework.Sample/Program.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 21 in samples/WeihanLi.EntityFramework.Sample/Program.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 21 in samples/WeihanLi.EntityFramework.Sample/Program.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// SoftDeleteTest();
// RepositoryTest();
RepositoryTest();
// AutoAuditTest();

await DbContextInterceptorSamples.RunAsync();
// await DbContextInterceptorSamples.RunAsync();

Console.WriteLine("completed");
Console.ReadLine();
Expand Down Expand Up @@ -212,7 +212,7 @@
var conn = db.Database.GetDbConnection();
try
{
conn.Execute($@"TRUNCATE TABLE {tableName}");
conn.Execute($"TRUNCATE TABLE {tableName}");
}
catch
{
Expand Down Expand Up @@ -241,6 +241,14 @@
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));

Expand Down
10 changes: 10 additions & 0 deletions samples/WeihanLi.EntityFramework.Sample/TestDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ public TestDbContext(DbContextOptions<TestDbContext> options) : base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<TestEntity>()
// .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<TestEntity> TestEntities { get; set; } = null!;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0" PrivateAssets="all" />
</ItemGroup>

</Project>
29 changes: 26 additions & 3 deletions src/WeihanLi.EntityFramework/EFRepositoryQueryBuilder.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -56,6 +53,28 @@ public EFRepositoryQueryBuilder<TEntity> IgnoreQueryFilters(bool ignoreQueryFilt
return this;
}

private readonly HashSet<string> _queryFiltersToIgnore = new();

public EFRepositoryQueryBuilder<TEntity> IgnoreQueryFilters(IReadOnlyCollection<string> 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<TEntity> WithCount(int count)
Expand Down Expand Up @@ -83,6 +102,10 @@ public IQueryable<TEntity> Build()
{
query = query.IgnoreQueryFilters();
}
else if (_queryFiltersToIgnore.Count > 0)
{
query = query.IgnoreQueryFilters(_queryFiltersToIgnore);
}
if (_whereExpression.Count > 0)
{
foreach (var expression in _whereExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="$(EFVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EFVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="xunit.v3" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit.v3" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading