Skip to content

Commit 7d72d63

Browse files
author
李明成
committed
版本升级-AA.dapper支持分页和复杂的查询
AA.dapper支持分页和复杂的查询
1 parent 024f394 commit 7d72d63

File tree

81 files changed

+4832
-198
lines changed

Some content is hidden

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

81 files changed

+4832
-198
lines changed

AA.AspNetCore/AA.AspNetCore.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<Description>AspNetCore 常用的</Description>
66
<PackageProjectUrl>https://github.com/ChengLab/AAFrameWork</PackageProjectUrl>
77
<RepositoryUrl>https://github.com/ChengLab/AAFrameWork</RepositoryUrl>
88
<RepositoryType>git</RepositoryType>
99
<PackageTags>netcore</PackageTags>
1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
11+
<Version>2.0.1</Version>
12+
<AssemblyVersion>2.0.1.0</AssemblyVersion>
13+
<FileVersion>2.0.1.0</FileVersion>
1114
</PropertyGroup>
1215

1316
<ItemGroup>
@@ -17,6 +20,10 @@
1720
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.5.0" />
1821
</ItemGroup>
1922

23+
<ItemGroup>
24+
<ProjectReference Include="..\AA.FrameWork\AA.FrameWork.csproj" />
25+
</ItemGroup>
26+
2027
<ItemGroup>
2128
<Reference Include="AA.FrameWork">
2229
<HintPath>..\AA.FrameWork\bin\Debug\netstandard2.0\AA.FrameWork.dll</HintPath>

AA.AspNetCore/CommonHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public static void SetProperty(object instance, string propertyName, object valu
200200
var instanceType = instance.GetType();
201201
var pi = instanceType.GetProperty(propertyName);
202202
if (pi == null)
203+
203204
throw new AAException("No property '{0}' found on the instance of type '{1}'.", propertyName, instanceType);
204205
if (!pi.CanWrite)
205206
throw new AAException("The property '{0}' on the instance of type '{1}' does not have a setter.", propertyName, instanceType);

AA.AspNetCore/Results/Result.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,48 @@ public class Result<T> : Result
1010
{
1111
public T Data { get; set; }
1212

13-
public static Result<T> Response(bool isSuccess, T data, string msg = "success")
13+
public static Result<T> Response(bool isSuccess, T data, string code = "", string msg = "")
1414
{
1515
return new Result<T>
1616
{
1717
IsSuccess = isSuccess,
1818
Message = msg,
19-
Data = data
19+
Code = code,
20+
Data = data
2021
};
2122
}
2223
}
2324
public class Result
2425
{
26+
2527
public bool IsSuccess { get; set; }
2628
public string Message { get; set; }
29+
public string Code { get; set; }
2730
public Result() { }
28-
public Result(bool isSuccess, string msg)
31+
public Result(bool isSuccess, string code, string msg)
2932
{
3033
this.IsSuccess = isSuccess;
3134
this.Message = msg;
35+
this.Code = code;
3236
}
33-
public static Result Success(string msg = "success")
37+
public static Result ResponseSuccess(string msg = "", string code = "")
3438
{
35-
return new Result(true, msg);
39+
return new Result(true, code, msg);
3640
}
3741

38-
public static Result Error(string message)
42+
public static Result ResponseError(string msg = "", string code = "")
43+
{
44+
return new Result(false, code, msg);
45+
}
46+
public static Result<T> Response<T>(bool isSuccess, T data, string code = "", string msg = "")
3947
{
40-
return new Result(false, message);
48+
return new Result<T>
49+
{
50+
IsSuccess = isSuccess,
51+
Message = msg,
52+
Code = code,
53+
Data = data
54+
};
4155
}
4256
}
4357
}

AA.AutoMapper/AA.AutoMapper.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>netstandard2.1</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
66
<Authors>ChengTian</Authors>
77
<Company>AA</Company>
@@ -11,7 +11,8 @@
1111
<PackageProjectUrl>https://github.com/ChengLab/AAFrameWork</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/ChengLab/AAFrameWork</RepositoryUrl>
1313
<RepositoryType>git</RepositoryType>
14-
<Version>1.0.1</Version>
14+
<Version>2.0.1</Version>
15+
<AssemblyVersion>2.0.1.0</AssemblyVersion>
1516
</PropertyGroup>
1617

1718
<ItemGroup>

AA.Dapper/AA.Dapper.csproj

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Authors>ChengTian</Authors>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<Authors>MingChengLi</Authors>
66
<Company>AA</Company>
77
<Product>AA</Product>
88
<Description>AA.Dapper 基于dapper+dommel 开发 , 支持工作单元、仓储模式和原生dapper的操作</Description>
@@ -11,9 +11,10 @@
1111
<RepositoryType>git</RepositoryType>
1212
<PackageTags>AA;Dapper;dommel;</PackageTags>
1313
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
14-
<AssemblyVersion>1.0.2.0</AssemblyVersion>
15-
<FileVersion>1.0.2.0</FileVersion>
16-
<Version>1.0.2</Version>
14+
<AssemblyVersion>2.0.5.0</AssemblyVersion>
15+
<FileVersion>2.0.5.0</FileVersion>
16+
<Version>2.0.5</Version>
17+
<LangVersion>preview</LangVersion>
1718
</PropertyGroup>
1819

1920
<ItemGroup>
@@ -27,17 +28,13 @@
2728
</ItemGroup>
2829

2930
<ItemGroup>
30-
<PackageReference Include="Dommel" Version="1.11.0" />
31+
<PackageReference Include="Dapper" Version="1.60.1" />
32+
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
3133
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
3234
</ItemGroup>
3335

3436
<ItemGroup>
3537
<ProjectReference Include="..\AA.FrameWork\AA.FrameWork.csproj" />
3638
</ItemGroup>
3739

38-
<ItemGroup>
39-
<Folder Include="FluentMap.Dommel\" />
40-
<Folder Include="FluentMap\" />
41-
</ItemGroup>
42-
4340
</Project>

AA.Dapper/Configuration/MapConfiguration.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
using AA.Dapper.FluentMap.Dommel;
44
using System;
55
using System.Collections.Generic;
6-
using System.Text;
76

87
namespace AA.Dapper.Configuration
98
{
10-
public static class MapConfiguration
9+
public static class MapConfiguration
1110
{
1211
public static void Init(List<Action<FluentMapConfiguration>> configures)
1312
{
14-
15-
FluentMapper.Initialize(config =>
13+
FluentMapper.Initialize(config =>
1614
{
1715
foreach (var a in configures)
1816
{
@@ -22,4 +20,4 @@ public static void Init(List<Action<FluentMapConfiguration>> configures)
2220
});
2321
}
2422
}
25-
}
23+
}

AA.Dapper/DbProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Data.SqlClient;
1010
using System.Reflection;
1111
using AA.Dapper.Util;
12+
using System.Collections.Concurrent;
1213

1314
namespace AA.Dapper
1415
{
@@ -17,14 +18,13 @@ public class DbProvider : IDbProvider
1718

1819
protected const string PropertyDbProvider = "quartz.dbprovider";
1920
//protected const string DbProviderSectionName = "quartz";
20-
protected const string DbProviderResourceName = "AA.Dapper.dbproviders.properties";
21+
protected const string DbProviderResourceName = "AA.Dapper.dbproviders.netstandard.properties";
2122

2223

2324
private readonly MethodInfo commandBindByNamePropertySetter;
2425

2526
private static readonly IList<DbMetadataFactory> dbMetadataFactories;
26-
private static readonly Dictionary<string, DbMetadata> dbMetadataLookup = new Dictionary<string, DbMetadata>();
27-
27+
private static readonly ConcurrentDictionary<string, DbMetadata> dbMetadataLookup = new ConcurrentDictionary<string, DbMetadata>();
2828
/// <summary>
2929
/// Parse metadata once in static constructor.
3030
/// </summary>

AA.Dapper/Dommel/Any.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using Dapper;
2+
using System;
3+
using System.Data;
4+
using System.Linq.Expressions;
5+
using System.Threading.Tasks;
6+
7+
namespace AA.Dapper.Dommel
8+
{
9+
public static partial class DommelMapper
10+
{
11+
/// <summary>
12+
/// Determines whether there's any entity of type <typeparamref name="TEntity"/> in the database.
13+
/// </summary>
14+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
15+
/// <param name="connection">The connection to the database. This can either be open or closed.</param>
16+
/// <param name="transaction">Optional transaction for the command.</param>
17+
/// <returns><c>true</c> if there's at least one entity in the database; otherwise, <c>false</c>.</returns>
18+
public static bool Any<TEntity>(this IDbConnection connection, IDbTransaction? transaction = null)
19+
{
20+
var sql = BuildAnyAllSql(GetSqlBuilder(connection), typeof(TEntity));
21+
LogQuery<TEntity>(sql);
22+
return connection.ExecuteScalar<bool>(sql, transaction);
23+
}
24+
25+
/// <summary>
26+
/// Determines whether there's any entity of type <typeparamref name="TEntity"/> in the database.
27+
/// </summary>
28+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
29+
/// <param name="connection">The connection to the database. This can either be open or closed.</param>
30+
/// <param name="transaction">Optional transaction for the command.</param>
31+
/// <returns><c>true</c> if there's at least one entity in the database; otherwise, <c>false</c>.</returns>
32+
public static Task<bool> AnyAsync<TEntity>(this IDbConnection connection, IDbTransaction? transaction = null)
33+
{
34+
var sql = BuildAnyAllSql(GetSqlBuilder(connection), typeof(TEntity));
35+
LogQuery<TEntity>(sql);
36+
return connection.ExecuteScalarAsync<bool>(sql, transaction);
37+
}
38+
39+
/// <summary>
40+
/// Determines whether there's any entity of type <typeparamref name="TEntity"/> matching the specified predicate in the database.
41+
/// </summary>
42+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
43+
/// <param name="connection">The connection to the database. This can either be open or closed.</param>
44+
/// <param name="predicate">A predicate to filter the results.</param>
45+
/// <param name="transaction">Optional transaction for the command.</param>
46+
/// <returns><c>true</c> if there's at least one entity in the database that matches the specified predicate; otherwise, <c>false</c>.</returns>
47+
public static bool Any<TEntity>(this IDbConnection connection, Expression<Func<TEntity, bool>> predicate, IDbTransaction? transaction = null)
48+
{
49+
var sql = BuildAnySql(GetSqlBuilder(connection), predicate, out var parameters);
50+
LogQuery<TEntity>(sql);
51+
return connection.ExecuteScalar<bool>(sql, parameters, transaction);
52+
}
53+
54+
/// <summary>
55+
/// Determines whether there's any entity of type <typeparamref name="TEntity"/> matching the specified predicate in the database.
56+
/// </summary>
57+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
58+
/// <param name="connection">The connection to the database. This can either be open or closed.</param>
59+
/// <param name="predicate">A predicate to filter the results.</param>
60+
/// <param name="transaction">Optional transaction for the command.</param>
61+
/// <returns><c>true</c> if there's at least one entity in the database that matches the specified predicate; otherwise, <c>false</c>.</returns>
62+
public static Task<bool> AnyAsync<TEntity>(this IDbConnection connection, Expression<Func<TEntity, bool>> predicate, IDbTransaction? transaction = null)
63+
{
64+
var sql = BuildAnySql(GetSqlBuilder(connection), predicate, out var parameters);
65+
LogQuery<TEntity>(sql);
66+
return connection.ExecuteScalarAsync<bool>(sql, parameters, transaction);
67+
}
68+
69+
private static string BuildAnyPredicate(ISqlBuilder sqlBuilder, Type type)
70+
{
71+
var cacheKey = new QueryCacheKey(QueryCacheType.Any, sqlBuilder, type);
72+
if (!QueryCache.TryGetValue(cacheKey, out var sql))
73+
{
74+
var tableName = Resolvers.Table(type, sqlBuilder);
75+
sql = $"select 1 from {tableName}";
76+
QueryCache.TryAdd(cacheKey, sql);
77+
}
78+
79+
return sql;
80+
}
81+
82+
internal static string BuildAnyAllSql(ISqlBuilder sqlBuilder, Type type)
83+
{
84+
var sql = $"{BuildAnyPredicate(sqlBuilder, type)} {sqlBuilder.LimitClause(1)}";
85+
return sql;
86+
}
87+
88+
internal static string BuildAnySql<TEntity>(ISqlBuilder sqlBuilder, Expression<Func<TEntity, bool>> predicate, out DynamicParameters parameters)
89+
{
90+
var sql = BuildAnyPredicate(sqlBuilder, typeof(TEntity));
91+
sql += CreateSqlExpression<TEntity>(sqlBuilder)
92+
.Where(predicate)
93+
.ToSql(out parameters);
94+
sql += $" {sqlBuilder.LimitClause(1)}";
95+
return sql;
96+
}
97+
}
98+
99+
}

0 commit comments

Comments
 (0)