This commit is contained in:
28810 2019-07-25 17:41:55 +08:00
parent 380534dfd5
commit 7460ffffaa
13 changed files with 16 additions and 17 deletions

View File

@ -42,7 +42,6 @@ public abstract class BaseEntity
/// <summary> /// <summary>
/// 开启工作单元事务 /// 开启工作单元事务
/// </summary> /// </summary>
/// <param name="level"></param>
/// <returns></returns> /// <returns></returns>
public static IUnitOfWork Begin() => Begin(null); public static IUnitOfWork Begin() => Begin(null);
public static IUnitOfWork Begin(IsolationLevel? level) public static IUnitOfWork Begin(IsolationLevel? level)
@ -118,28 +117,28 @@ public abstract class BaseEntity<TEntity> : BaseEntity where TEntity : class
/// <summary> /// <summary>
/// 插入数据 /// 插入数据
/// </summary> /// </summary>
async public virtual Task Insert() public virtual Task<TEntity> Insert()
{ {
this.CreateTime = DateTime.Now; this.CreateTime = DateTime.Now;
if (this.Repository == null) if (this.Repository == null)
this.Repository = Orm.GetRepository<TEntity>(); this.Repository = Orm.GetRepository<TEntity>();
this.Repository.UnitOfWork = UnitOfWork.Current.Value; this.Repository.UnitOfWork = UnitOfWork.Current.Value;
await this.Repository.InsertAsync(this as TEntity); return this.Repository.InsertAsync(this as TEntity);
} }
/// <summary> /// <summary>
/// 更新或插入 /// 更新或插入
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
async public virtual Task Save() public virtual Task<TEntity> Save()
{ {
this.UpdateTime = DateTime.Now; this.UpdateTime = DateTime.Now;
if (this.Repository == null) if (this.Repository == null)
this.Repository = Orm.GetRepository<TEntity>(); this.Repository = Orm.GetRepository<TEntity>();
this.Repository.UnitOfWork = UnitOfWork.Current.Value; this.Repository.UnitOfWork = UnitOfWork.Current.Value;
await this.Repository.InsertOrUpdateAsync(this as TEntity); return this.Repository.InsertOrUpdateAsync(this as TEntity);
} }
} }

View File

@ -11,7 +11,8 @@ namespace base_entity
{ {
using (var uow = BaseEntity.Begin()) using (var uow = BaseEntity.Begin())
{ {
var itt = await UserGroup.Find(1); var id = (await new User1().Save()).Id;
uow.Commit();
} }
var ug1 = new UserGroup(); var ug1 = new UserGroup();

View File

@ -23,7 +23,6 @@
<summary> <summary>
开启工作单元事务 开启工作单元事务
</summary> </summary>
<param name="level"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:BaseEntity`1.Delete"> <member name="M:BaseEntity`1.Delete">

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 扩展包,可实现【延时加载】属性.</Description> <Description>FreeSql 扩展包,可实现【延时加载】属性.</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description> <Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite, and read/write separation、and split table.</Description> <Description>FreeSql Implementation of General Repository, Support MySql/SqlServer/PostgreSQL/Oracle/Sqlite, and read/write separation、and split table.</Description>
<PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl> <PackageProjectUrl>https://github.com/2881099/FreeSql/wiki/Repository</PackageProjectUrl>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description> <Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks> <TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 MySql 5.6</Description> <Description>FreeSql 数据库实现,基于 MySql 5.6</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 MySql 5.6</Description> <Description>FreeSql 数据库实现,基于 MySql 5.6</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 Oracle 11</Description> <Description>FreeSql 数据库实现,基于 Oracle 11</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 PostgreSQL 9.5</Description> <Description>FreeSql 数据库实现,基于 PostgreSQL 9.5</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net451</TargetFrameworks> <TargetFrameworks>netstandard2.0;net451</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 SqlServer 2005+并根据版本适配分页方法row_number 或 offset fetch next</Description> <Description>FreeSql 数据库实现,基于 SqlServer 2005+并根据版本适配分页方法row_number 或 offset fetch next</Description>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Version>0.7.15</Version> <Version>0.7.16</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 数据库实现,基于 Sqlite 3.0</Description> <Description>FreeSql 数据库实现,基于 Sqlite 3.0</Description>