Skip to content

Commit

Permalink
- 移除 fsql.GetGuidRepository 改用 fsql.GetRepository<T, Guid>();
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Aug 18, 2024
1 parent d3904ff commit c01b4c8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
12 changes: 12 additions & 0 deletions Examples/repository_01/Controllers/SongController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ IBaseRepository<TestSoftDelete> reposTest
Console.Write(reposTest.Select.ToSql());

_songRepository = repos4;

//test code
var curd1 = fsql.GetRepository<Song, int>();
var curd2 = fsql.GetRepository<Song, string>();
var curd3 = fsql.GetRepository<Song, Guid>();

Console.WriteLine(reposSong.Select.ToSql());

using (reposSong.DataFilter.DisableAll())
{
Console.WriteLine(reposSong.Select.ToSql());
}
}

[HttpGet]
Expand Down
1 change: 0 additions & 1 deletion FreeSql.Tests/FreeSql.Tests/FreeSql.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Npgsql" Version="6.0.11" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.5" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand Down
68 changes: 34 additions & 34 deletions FreeSql.Tests/FreeSql.Tests/Issues/1208.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ public void GlobalFilter01()
limit 0,1))
ORDER BY a.""Id"" DESC", sql);

// using (userRepository.DataFilter.Disable("TenantQuery"))
// {
// sql = userRepository.Select
// .Where(i => i.DoorDevices.AsSelect().Any(x => x.Id == deviceId))
// .OrderByDescending(true, a => a.Id)
// .ToSql();
// Assert.Equal(@"SELECT a.""Id"", a.""TenantId""
//FROM ""issues1208_User"" a
//WHERE (exists(SELECT 1
// FROM ""issues1208_DoorDeviceUser"" Mx_Mi
// WHERE (Mx_Mi.""UserId"" = a.""Id"") AND (exists(SELECT 1
// FROM ""issues1208_DoorDevice"" x
// WHERE (x.""Id"" = 100) AND (x.""Id"" = Mx_Mi.""DoorDeviceId"")
// limit 0,1))
// limit 0,1))
//ORDER BY a.""Id"" DESC", sql);
// }
using (userRepository.DataFilter.Disable("TenantQuery"))
{
sql = userRepository.Select
.Where(i => i.DoorDevices.AsSelect().Any(x => x.Id == deviceId))
.OrderByDescending(true, a => a.Id)
.ToSql();
Assert.Equal(@"SELECT a.""Id"", a.""TenantId""
FROM ""issues1208_User"" a
WHERE (exists(SELECT 1
FROM ""issues1208_DoorDeviceUser"" Mx_Mi
WHERE (Mx_Mi.""UserId"" = a.""Id"") AND (exists(SELECT 1
FROM ""issues1208_DoorDevice"" x
WHERE (x.""Id"" = 100) AND (x.""Id"" = Mx_Mi.""DoorDeviceId"")
limit 0,1))
limit 0,1))
ORDER BY a.""Id"" DESC", sql);
}

sql = userRepository.Select
.Where(i => i.DoorDevices.Any(x => x.Id == deviceId))
Expand Down Expand Up @@ -113,23 +113,23 @@ public void GlobalFilter01()
limit 0,1))
ORDER BY a.""Id"" DESC", sql);

// using (userRepository.DataFilter.Disable("TenantQuery"))
// {
// sql = userRepository.Select
// .Where(i => i.DoorDevices.Any(x => x.Id == deviceId))
// .OrderByDescending(true, a => a.Id)
// .ToSql();
// Assert.Equal(@"SELECT a.""Id"", a.""TenantId""
//FROM ""issues1208_User"" a
//WHERE (exists(SELECT 1
// FROM ""issues1208_DoorDevice"" x
// WHERE (exists(SELECT 1
// FROM ""issues1208_DoorDeviceUser"" Mx_Ma
// WHERE (Mx_Ma.""DoorDeviceId"" = x.""Id"") AND (Mx_Ma.""UserId"" = a.""Id"")
// limit 0,1)) AND (x.""Id"" = 100)
// limit 0,1))
//ORDER BY a.""Id"" DESC", sql);
// }
using (userRepository.DataFilter.Disable("TenantQuery"))
{
sql = userRepository.Select
.Where(i => i.DoorDevices.Any(x => x.Id == deviceId))
.OrderByDescending(true, a => a.Id)
.ToSql();
Assert.Equal(@"SELECT a.""Id"", a.""TenantId""
FROM ""issues1208_User"" a
WHERE (exists(SELECT 1
FROM ""issues1208_DoorDevice"" x
WHERE (exists(SELECT 1
FROM ""issues1208_DoorDeviceUser"" Mx_Ma
WHERE (Mx_Ma.""DoorDeviceId"" = x.""Id"") AND (Mx_Ma.""UserId"" = a.""Id"")
limit 0,1)) AND (x.""Id"" = 100)
limit 0,1))
ORDER BY a.""Id"" DESC", sql);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions FreeSql.Tests/FreeSql.Tests/UnitTest2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,16 @@ public void Test02()
var gft2 = g.mysql.Select<gf_t2>().Where(a => a.id == Guid.NewGuid()).ToList();
var gft3 = g.mysql.Select<gf_t3>().Where(a => a.id == Guid.NewGuid()).ToList();

var repo1 = g.mysql.GetRepository<gf_t1, Guid>();
using (repo1.DataFilter.Disable("gft1", "gft2", "gft3"))
repo1.Get(Guid.NewGuid());
var repo2 = g.mysql.GetRepository<gf_t2, Guid>();
using (repo2.DataFilter.Disable("gft1", "gft2", "gft3"))
repo2.Get(Guid.NewGuid());
var repo3 = g.mysql.GetRepository<gf_t3, Guid>();
using (repo3.DataFilter.Disable("gft1", "gft2", "gft3"))
repo3.Get(Guid.NewGuid());

g.sqlserver.Delete<TBatInst>().Where("1=1").ExecuteAffrows();
g.mysql.Delete<TBatInst>().Where("1=1").ExecuteAffrows();
g.pgsql.Delete<TBatInst>().Where("1=1").ExecuteAffrows();
Expand Down
1 change: 0 additions & 1 deletion FreeSql.Tests/FreeSql.Tests/g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Npgsql;
using Npgsql.Internal;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down

0 comments on commit c01b4c8

Please sign in to comment.