mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 04:18:16 +08:00
优化 FreeSql.Repository 使用方法
This commit is contained in:
@ -40,7 +40,7 @@ namespace FreeSql {
|
||||
}
|
||||
}
|
||||
|
||||
public virtual List<TEntity> Insert(List<TEntity> entity) {
|
||||
public virtual List<TEntity> Insert(IEnumerable<TEntity> entity) {
|
||||
switch (_fsql.Ado.DataType) {
|
||||
case DataType.SqlServer:
|
||||
case DataType.PostgreSQL:
|
||||
@ -66,7 +66,7 @@ namespace FreeSql {
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Task<List<TEntity>> InsertAsync(List<TEntity> entity) {
|
||||
public virtual Task<List<TEntity>> InsertAsync(IEnumerable<TEntity> entity) {
|
||||
switch (_fsql.Ado.DataType) {
|
||||
case DataType.SqlServer:
|
||||
case DataType.PostgreSQL:
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.1.5</Version>
|
||||
<Version>0.1.5.3</Version>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql 通用仓库层现实,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
|
||||
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -11,14 +12,14 @@ namespace FreeSql {
|
||||
public GuidRepository(IFreeSql fsql) : base(fsql) {
|
||||
}
|
||||
|
||||
public override List<TEntity> Insert(List<TEntity> entity) {
|
||||
public override List<TEntity> Insert(IEnumerable<TEntity> entity) {
|
||||
_fsql.Insert<TEntity>().AppendData(entity).ExecuteAffrows();
|
||||
return entity;
|
||||
return entity.ToList();
|
||||
}
|
||||
|
||||
async public override Task<List<TEntity>> InsertAsync(List<TEntity> entity) {
|
||||
async public override Task<List<TEntity>> InsertAsync(IEnumerable<TEntity> entity) {
|
||||
await _fsql.Insert<TEntity>().AppendData(entity).ExecuteAffrowsAsync();
|
||||
return entity;
|
||||
return entity.ToList();
|
||||
}
|
||||
|
||||
public override TEntity Insert(TEntity entity) {
|
||||
|
@ -6,11 +6,11 @@ namespace FreeSql {
|
||||
where TEntity : class {
|
||||
TEntity Insert(TEntity entity);
|
||||
|
||||
List<TEntity> Insert(List<TEntity> entity);
|
||||
List<TEntity> Insert(IEnumerable<TEntity> entity);
|
||||
|
||||
Task<TEntity> InsertAsync(TEntity entity);
|
||||
|
||||
Task<List<TEntity>> InsertAsync(List<TEntity> entity);
|
||||
Task<List<TEntity>> InsertAsync(IEnumerable<TEntity> entity);
|
||||
|
||||
int Update(TEntity entity);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using FreeSql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text;
|
||||
|
||||
public static class IFreeSqlExtenssions {
|
||||
@ -12,10 +13,12 @@ public static class IFreeSqlExtenssions {
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <param name="that"></param>
|
||||
/// <returns></returns>
|
||||
public static IRepository<TEntity, TKey> GetRepository<TEntity, TKey>(this IFreeSql that) where TEntity : class {
|
||||
public static DefaultRepository<TEntity, TKey> GetRepository<TEntity, TKey>(this IFreeSql that) where TEntity : class {
|
||||
|
||||
return new DefaultRepository<TEntity, TKey>(that);
|
||||
return dicGetRepository.GetOrAdd(typeof(TEntity), type1 => new ConcurrentDictionary<Type, IRepository>())
|
||||
.GetOrAdd(typeof(TKey), type2 => new DefaultRepository<TEntity, TKey>(that)) as DefaultRepository<TEntity, TKey>;
|
||||
}
|
||||
static ConcurrentDictionary<Type, ConcurrentDictionary<Type, IRepository>> dicGetRepository = new ConcurrentDictionary<Type, ConcurrentDictionary<Type, IRepository>>();
|
||||
|
||||
/// <summary>
|
||||
/// 返回仓库类,适用 Insert 方法无须返回插入的数据
|
||||
@ -23,8 +26,9 @@ public static class IFreeSqlExtenssions {
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <param name="that"></param>
|
||||
/// <returns></returns>
|
||||
public static IRepository<TEntity, Guid> GetGuidRepository<TEntity>(this IFreeSql that) where TEntity : class {
|
||||
public static GuidRepository<TEntity> GetGuidRepository<TEntity>(this IFreeSql that) where TEntity : class {
|
||||
|
||||
return new GuidRepository<TEntity>(that);
|
||||
return dicGetGuidRepository.GetOrAdd(typeof(TEntity), type1 => new GuidRepository<TEntity>(that)) as GuidRepository<TEntity>;
|
||||
}
|
||||
static ConcurrentDictionary<Type, IRepository> dicGetGuidRepository = new ConcurrentDictionary<Type, IRepository>();
|
||||
}
|
Reference in New Issue
Block a user