Skip to content

Commit eb4da76

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 9dd1272 + c1dd669 commit eb4da76

File tree

1,034 files changed

+156513
-26417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,034 files changed

+156513
-26417
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ dotnet_analyzer_diagnostic.category-Style.severity = none
55

66
# CS0649: 从未对字段“TransactionalAttribute._uowManager”赋值,字段将一直保持其默认值 null
77
dotnet_diagnostic.CS0649.severity = none
8+
9+
# CS8618: 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
10+
dotnet_diagnostic.CS8618.severity = none
11+
12+
charset = utf-8-bom
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: "Bug Report 🐛"
3+
about: 这里只能提交 Bug,提交其他无关信息会被关闭
4+
title: ''
5+
labels: Bug
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
以下为必读项,不仔细阅读会导致你的 Issue 被关闭
12+
13+
1. 该分类下只能提交 Bug,如果要询问使用方法等,请前往讨论区:https://github.com/dotnetcore/FreeSql/discussions
14+
2. FreeSql写了许多文档,在提问题前,麻烦先查看[常见问题](https://freesql.net/reference/faq.html)
15+
3. 不完整的信息将不会得到任何回复!发布问题后,请保持对 issue 的关注,有时会有需要进一步沟通的信息,很长时间内没有得到答复的 issue 将被关闭。
16+
4. 提供可重现的代码,至少应描述以下信息 -->
17+
18+
#### 问题描述及重现代码:
19+
20+
```c#
21+
// c# code
22+
```
23+
24+
#### 数据库版本
25+
26+
27+
#### 安装的Nuget包
28+
29+
30+
#### .net framework/. net core? 及具体版本
31+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: "Feature Request 🚀"
3+
about: 这里只能提交 Feature 请求,提交其他无关信息会被关闭
4+
title: ''
5+
labels: Feature
6+
assignees: ''
7+
8+
---
9+
10+
<!--
11+
以下为必读项,不仔细阅读会导致你的 Issue 被关闭
12+
13+
1. 该分类下只能提交 Feature,如果要询问使用方法等,请前往讨论区:https://github.com/dotnetcore/FreeSql/discussions
14+
2. 请尽量详细的描述清楚你的需求
15+
-->
16+
17+
#### Feature 特性
18+
19+
```c#
20+
// c# code
21+
```
22+
23+
#### 简要描述原因
24+
25+
```c#
26+
// c# code
27+
```
28+
29+
#### 使用场景
30+
31+
```c#
32+
// c# code
33+
```

.github/workflows/docfx.yml

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,33 @@
1-
name: .NET Core Deploy Docfx
1+
name: Docfx Deploy
22

33
on:
4-
push:
5-
branches: [master]
6-
pull_request:
7-
branches: [master]
8-
4+
workflow_dispatch:
5+
push:
6+
branches: [master]
7+
98
jobs:
10-
build:
11-
runs-on: ubuntu-latest
12-
13-
steps:
14-
- name: Checkout
15-
uses: actions/checkout@v2
16-
- name: Setup .NET Core
17-
uses: actions/setup-dotnet@v1
18-
with:
19-
dotnet-version: 5.0.202
20-
- name: Exclude example projects
21-
run: dotnet sln FreeSql.sln remove Examples/**/*.csproj FreeSql.Tests/**/*.csproj
22-
- name: Install dependencies
23-
run: dotnet restore
24-
- name: Build solution
25-
run: dotnet build --configuration Release --no-restore
26-
279
generate-docs:
2810
runs-on: windows-latest
29-
needs: build
3011

3112
steps:
3213
- name: Checkout
3314
uses: actions/checkout@v2
3415
- name: Setup .NET Core
3516
uses: actions/setup-dotnet@v1
36-
with:
37-
dotnet-version: 5.0.202
17+
with:
18+
dotnet-version: 7.0.x
3819
- name: Remove Examples
3920
run: dotnet sln FreeSql.sln remove (ls -r Examples/**/*.csproj)
4021
- name: Remove FreeSql.Tests
4122
run: dotnet sln FreeSql.sln remove (ls -r FreeSql.Tests/**/*.csproj)
4223
- name: Install dependencies
43-
run: dotnet restore
24+
run: dotnet restore .\FreeSql.sln
25+
- name: Build solution
26+
run: dotnet build --configuration Release --no-restore .\FreeSql.sln
4427
- name: Setup DocFX
4528
uses: crazy-max/ghaction-chocolatey@v1
4629
with:
47-
args: install docfx --version 2.56.7
30+
args: install docfx
4831
- name: DocFX Build
4932
working-directory: docs
5033
run: docfx docfx.json

Directory.Build.props

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
<Project>
2-
1+
<Project>
32
<PropertyGroup>
43
<RepositoryUrl>https://github.com/dotnetcore/FreeSql</RepositoryUrl>
4+
<IncludeSymbols>true</IncludeSymbols>
5+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
56
<PublishRepositoryUrl>true</PublishRepositoryUrl>
67
<EmbedUntrackedSources>true</EmbedUntrackedSources>
78
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
9+
<NoWarn>1701;1702;CS1573;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8618;CS8619;CS8620;CS8622;CS8625;CS8629;CS8714;CS1591;CS0649;CA2200</NoWarn>
810
</PropertyGroup>
911

12+
<!--
13+
经常出于版本交叉问题,暂时关闭,在每个项目上设置版本号
14+
<PropertyGroup>
15+
<Version>3.5.210-preview20250626</Version>
16+
</PropertyGroup>
17+
-->
18+
1019
<ItemGroup>
1120
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
1221
</ItemGroup>
16 KB
Binary file not shown.
Lines changed: 20 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using FreeSql;
1+
using System;
2+
using System.ComponentModel;
3+
using System.Threading.Tasks;
4+
using FreeSql;
25
using FreeSql.DataAnnotations;
36
using Microsoft.AspNetCore.Mvc;
4-
using Microsoft.Extensions.DependencyInjection;
57
using Microsoft.Extensions.Logging;
6-
using System.ComponentModel;
7-
using System.Linq;
8-
using System.Reflection;
9-
using System.Threading;
10-
using System.Threading.Tasks;
118

129
namespace aspnetcore_transaction.Controllers
1310
{
@@ -24,24 +21,25 @@ public HomeController(ILogger<HomeController> logger)
2421

2522
[HttpGet("1")]
2623
//[Transactional]
27-
virtual public object Get([FromServices] BaseRepository<Song> repoSong, [FromServices] BaseRepository<Detail> repoDetail, [FromServices] SongRepository repoSong2,
24+
public async Task<object> Get([FromServices] BaseRepository<Song> repoSong, [FromServices] BaseRepository<Detail> repoDetail, [FromServices] SongRepository repoSong2,
2825
[FromServices] SongService serviceSong)
2926
{
3027
//repoSong.Insert(new Song());
3128
//repoDetail.Insert(new Detail());
3229
//repoSong2.Insert(new Song());
3330

34-
serviceSong.Test1();
31+
//serviceSong.Test1();
32+
await serviceSong.Test11();
3533
return "111";
3634
}
3735

3836
[HttpGet("2")]
39-
//[Transactional]
40-
async virtual public Task<object> GetAsync([FromServices] BaseRepository<Song> repoSong, [FromServices] BaseRepository<Detail> repoDetail, [FromServices] SongRepository repoSong2,
37+
[Transactional]
38+
public async Task<object> GetAsync([FromServices] BaseRepository<Song> repoSong, [FromServices] BaseRepository<Detail> repoDetail, [FromServices] SongRepository repoSong2,
4139
[FromServices] SongService serviceSong)
4240
{
43-
await serviceSong.Test2();
44-
await serviceSong.Test3();
41+
await repoSong.InsertAsync(new Song());
42+
await repoDetail.InsertAsync(new Detail());
4543
return "111";
4644
}
4745
}
@@ -61,23 +59,29 @@ public SongService(BaseRepository<Song> repoSong, BaseRepository<Detail> repoDet
6159
}
6260

6361
[Transactional(Propagation = Propagation.Nested)] //sqlite 不能嵌套事务,会锁库的
64-
public virtual void Test1()
62+
public void Test1()
6563
{
6664
_repoSong.Insert(new Song());
6765
_repoDetail.Insert(new Detail());
6866
_repoSong2.Insert(new Song());
6967
}
68+
[Transactional(Propagation = Propagation.Nested)] //sqlite 不能嵌套事务,会锁库的
69+
public Task Test11()
70+
{
71+
return Task.Delay(TimeSpan.FromSeconds(1)).ContinueWith(t =>
72+
_repoSong.InsertAsync(new Song()));
73+
}
7074

7175
[Transactional(Propagation = Propagation.Nested)] //sqlite 不能嵌套事务,会锁库的
72-
async public virtual Task Test2()
76+
public async Task Test2()
7377
{
7478
await _repoSong.InsertAsync(new Song());
7579
await _repoDetail.InsertAsync(new Detail());
7680
await _repoSong2.InsertAsync(new Song());
7781
}
7882

7983
[Transactional(Propagation = Propagation.Nested)] //sqlite 不能嵌套事务,会锁库的
80-
async public virtual Task<object> Test3()
84+
public async Task<object> Test3()
8185
{
8286
await _repoSong.InsertAsync(new Song());
8387
await _repoDetail.InsertAsync(new Detail());
@@ -110,53 +114,4 @@ public class Detail
110114
public int SongId { get; set; }
111115
public string Title { get; set; }
112116
}
113-
114-
public static class IdleBusExtesions
115-
{
116-
static AsyncLocal<string> AsyncLocalTenantId = new AsyncLocal<string>();
117-
public static IdleBus<IFreeSql> ChangeTenant(this IdleBus<IFreeSql> ib, string tenantId)
118-
{
119-
AsyncLocalTenantId.Value = tenantId;
120-
return ib;
121-
}
122-
public static IFreeSql Get(this IdleBus<IFreeSql> ib) => ib.Get(AsyncLocalTenantId.Value ?? "default");
123-
public static IBaseRepository<T> GetRepository<T>(this IdleBus<IFreeSql> ib) where T : class => ib.Get().GetRepository<T>();
124-
125-
static void test()
126-
{
127-
IdleBus<IFreeSql> ib = null; //单例注入
128-
129-
var fsql = ib.Get(); //获取当前租户对应的 IFreeSql
130-
131-
var fsql00102 = ib.ChangeTenant("00102").Get(); //切换租户,后面的操作都是针对 00102
132-
133-
var songRepository = ib.GetRepository<Song>();
134-
var detailRepository = ib.GetRepository<Detail>();
135-
}
136-
137-
public static IServiceCollection AddRepository(this IServiceCollection services, params Assembly[] assemblies)
138-
{
139-
services.AddScoped(typeof(IBaseRepository<>), typeof(YourDefaultRepository<>));
140-
services.AddScoped(typeof(BaseRepository<>), typeof(YourDefaultRepository<>));
141-
142-
services.AddScoped(typeof(IBaseRepository<,>), typeof(YourDefaultRepository<,>));
143-
services.AddScoped(typeof(BaseRepository<,>), typeof(YourDefaultRepository<,>));
144-
145-
if (assemblies?.Any() == true)
146-
foreach (var asse in assemblies)
147-
foreach (var repo in asse.GetTypes().Where(a => a.IsAbstract == false && typeof(IBaseRepository).IsAssignableFrom(a)))
148-
services.AddScoped(repo);
149-
150-
return services;
151-
}
152-
}
153-
154-
class YourDefaultRepository<T> : BaseRepository<T> where T : class
155-
{
156-
public YourDefaultRepository(IdleBus<IFreeSql> ib) : base(ib.Get(), null, null) { }
157-
}
158-
class YourDefaultRepository<T, TKey> : BaseRepository<T, TKey> where T : class
159-
{
160-
public YourDefaultRepository(IdleBus<IFreeSql> ib) : base(ib.Get(), null, null) { }
161-
}
162117
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Threading.Tasks;
4+
using FreeSql;
5+
using FreeSql.DataAnnotations;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Logging;
8+
9+
namespace aspnetcore_transaction.Domain
10+
{
11+
public class SongRepository : DefaultRepository<Song, int>
12+
{
13+
public SongRepository(UnitOfWorkManager uowm) : base(uowm?.Orm, uowm) { }
14+
}
15+
16+
[Description("123")]
17+
public class Song
18+
{
19+
/// <summary>
20+
/// 自增
21+
/// </summary>
22+
[Column(IsIdentity = true)]
23+
[Description("自增id")]
24+
public int Id { get; set; }
25+
public string Title { get; set; }
26+
}
27+
public class Detail
28+
{
29+
[Column(IsIdentity = true)]
30+
public int Id { get; set; }
31+
32+
public int SongId { get; set; }
33+
public string Title { get; set; }
34+
}
35+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2+
<Rougamo />
3+
</Weavers>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
4+
<xs:element name="Weavers">
5+
<xs:complexType>
6+
<xs:all>
7+
<xs:element name="Rougamo" minOccurs="0" maxOccurs="1" type="xs:anyType" />
8+
</xs:all>
9+
<xs:attribute name="VerifyAssembly" type="xs:boolean">
10+
<xs:annotation>
11+
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
12+
</xs:annotation>
13+
</xs:attribute>
14+
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
15+
<xs:annotation>
16+
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
17+
</xs:annotation>
18+
</xs:attribute>
19+
<xs:attribute name="GenerateXsd" type="xs:boolean">
20+
<xs:annotation>
21+
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
22+
</xs:annotation>
23+
</xs:attribute>
24+
</xs:complexType>
25+
</xs:element>
26+
</xs:schema>

0 commit comments

Comments
 (0)