Skip to content

Commit

Permalink
🔖 1.23.10824.11402
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Aug 24, 2023
1 parent f06a743 commit 51ec33f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,18 @@ protected virtual IQueryable<TViewModel> Cast<TViewModel>(IQueryable<TEntity> qu
// EF Core 2.0 中已引入此行为。 对于早期版本,始终需要显式选择 Add 或 Update。
if (IsAutoGeneratedKey)
{
DbRowExecResult dbRowExecResult;
var primaryKey = GetPrimaryKey(entity);
if (IRepository<TEntity, TPrimaryKey>.IsDefault(primaryKey))
{
dbRowExecResult = DbRowExecResult.Insert;
}
else
{
dbRowExecResult = DbRowExecResult.Update;
}
var rowCount = await UpdateAsync(entity, cancellationToken);
return (rowCount, DbRowExecResult.InsertOrUpdate);
return (rowCount, dbRowExecResult);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,22 @@ Task<int> CountAsync(CancellationToken t)
public virtual async Task<(int rowCount, DbRowExecResult result)> InsertOrUpdateAsync(TEntity entity, CancellationToken cancellationToken = default)
{
var dbConnection = await GetDbConnection().ConfigureAwait(false);
var rowCount = await AttemptAndRetry(t =>
var r = await AttemptAndRetry(async t =>
{
t.ThrowIfCancellationRequested();
var primaryKey = GetPrimaryKey(entity);
if (IRepository<TEntity, TPrimaryKey>.IsDefault(primaryKey))
{
return dbConnection.InsertAsync(entity);
var rowCount = await dbConnection.InsertAsync(entity);
return (rowCount, DbRowExecResult.Insert);
}
else
{
return dbConnection.InsertOrReplaceAsync(entity);
var rowCount = await dbConnection.InsertOrReplaceAsync(entity);
return (rowCount, DbRowExecResult.Update);
}
}, cancellationToken: cancellationToken).ConfigureAwait(false);
return (rowCount, DbRowExecResult.InsertOrUpdate);
return r;
}

#endregion
Expand Down
5 changes: 0 additions & 5 deletions src/BD.Common.Repositories/Enums/DbRowExecResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,4 @@ public enum DbRowExecResult : byte
/// 删除
/// </summary>
Delete,

/// <summary>
/// 插入或更新
/// </summary>
InsertOrUpdate,
}
2 changes: 1 addition & 1 deletion src/BD.Common/Text/Encoding2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void RegisterCodePagesProvider()
=> Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

/// <summary>
/// 获取 GB 2312 编码
/// 获取 GB2312 编码
/// </summary>
/// <returns></returns>
public static Encoding GB2312 => GB2312_;
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<IsTrimmable>true</IsTrimmable>
<!--<Version>1.yy.1MMdd.1hhmm</Version>-->
<Version>1.23.10823.11451</Version>
<Version>1.23.10824.11402</Version>
<PackageIconUrl>https://avatars.githubusercontent.com/u/79355691?s=200&amp;v=4</PackageIconUrl>
<Company>江苏蒸汽凡星科技有限公司</Company>
<Copyright>©️ $(Company). All rights reserved.</Copyright>
Expand Down

0 comments on commit 51ec33f

Please sign in to comment.