Skip to content

Commit

Permalink
Modified CreationProvider to retrieve the key of the newly inserted r…
Browse files Browse the repository at this point in the history
…ecord
  • Loading branch information
Yuck committed Jul 13, 2021
1 parent e6814dd commit ed34740
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>0.8.2</Version>
<Version>0.8.3</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>An implementation of YuckQi.Data using Dapper for MySQL.</Description>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>0.8.2</Version>
<Version>0.8.3</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>An implementation of YuckQi.Data using Dapper and SimpleCRUD for MSSQL.</Description>
</PropertyGroup>
Expand Down
14 changes: 10 additions & 4 deletions src/YuckQi.Data.Sql.Dapper/Providers/CreationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public TEntity Create(TEntity entity, IDbTransaction transaction)

entity.CreationMomentUtc = DateTime.UtcNow;

if (! (transaction.Connection.Insert(entity.Adapt<TRecord>(), transaction) > 0))
throw new RecordInsertException<TKey>();
var key = transaction.Connection.Insert<TKey?, TRecord>(entity.Adapt<TRecord>(), transaction);
if (key == null)
throw new RecordInsertException<TRecord>();

entity.Key = key.Value;

return entity;
}
Expand All @@ -38,8 +41,11 @@ public async Task<TEntity> CreateAsync(TEntity entity, IDbTransaction transactio

entity.CreationMomentUtc = DateTime.UtcNow;

if (! (await transaction.Connection.InsertAsync(entity.Adapt<TRecord>(), transaction) > 0))
throw new RecordInsertException<TKey>();
var key = await transaction.Connection.InsertAsync<TKey?, TRecord>(entity.Adapt<TRecord>(), transaction);
if (key == null)
throw new RecordInsertException<TRecord>();

entity.Key = key.Value;

return entity;
}
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data.Sql.Dapper/YuckQi.Data.Sql.Dapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>0.8.2</Version>
<Version>0.8.3</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>An implementation of YuckQi.Data using Dapper.</Description>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>0.8.2</Version>
<Version>0.8.3</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>An implementation of YuckQi.Data using Entity Framework.</Description>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data/YuckQi.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>0.8.2</Version>
<Version>0.8.3</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>A .NET library providing fine-grained data providers useful in data repository or domain service implementations.</Description>
</PropertyGroup>
Expand Down

0 comments on commit ed34740

Please sign in to comment.