mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
v0.1.3
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
@ -18,21 +19,69 @@ namespace FreeSql {
|
||||
|
||||
public IUpdate<TEntity> UpdateDiy => _fsql.Update<TEntity>();
|
||||
|
||||
public void Delete(Expression<Func<TEntity, bool>> predicate) => _fsql.Delete<TEntity>().Where(predicate).ExecuteAffrows();
|
||||
public int Delete(Expression<Func<TEntity, bool>> predicate) => _fsql.Delete<TEntity>().Where(predicate).ExecuteAffrows();
|
||||
|
||||
public void Delete(TEntity entity) => _fsql.Delete<TEntity>(entity).ExecuteAffrows();
|
||||
public int Delete(TEntity entity) => _fsql.Delete<TEntity>(entity).ExecuteAffrows();
|
||||
|
||||
public Task DeleteAsync(Expression<Func<TEntity, bool>> predicate) => _fsql.Delete<TEntity>().Where(predicate).ExecuteAffrowsAsync();
|
||||
public Task<int> DeleteAsync(Expression<Func<TEntity, bool>> predicate) => _fsql.Delete<TEntity>().Where(predicate).ExecuteAffrowsAsync();
|
||||
|
||||
public Task DeleteAsync(TEntity entity) => _fsql.Delete<TEntity>(entity).ExecuteAffrowsAsync();
|
||||
public Task<int> DeleteAsync(TEntity entity) => _fsql.Delete<TEntity>(entity).ExecuteAffrowsAsync();
|
||||
|
||||
public TEntity Insert(TEntity entity) => _fsql.Insert<TEntity>().AppendData(entity).ExecuteInserted().FirstOrDefault();
|
||||
public virtual TEntity Insert(TEntity entity) {
|
||||
switch (_fsql.Ado.DataType) {
|
||||
case DataType.SqlServer:
|
||||
case DataType.PostgreSQL:
|
||||
return _fsql.Insert<TEntity>().AppendData(entity).ExecuteInserted().FirstOrDefault();
|
||||
case DataType.MySql:
|
||||
case DataType.Oracle:
|
||||
case DataType.Sqlite:
|
||||
default:
|
||||
throw new NotImplementedException($"{_fsql.Ado.DataType}不支持类似returning或output类型的特性,请参考FreeSql插入数据的方法重新现实。");
|
||||
}
|
||||
}
|
||||
|
||||
async public Task<TEntity> InsertAsync(TEntity entity) => (await _fsql.Insert<TEntity>().AppendData(entity).ExecuteInsertedAsync()).FirstOrDefault();
|
||||
public virtual List<TEntity> Insert(List<TEntity> entity) {
|
||||
switch (_fsql.Ado.DataType) {
|
||||
case DataType.SqlServer:
|
||||
case DataType.PostgreSQL:
|
||||
return _fsql.Insert<TEntity>().AppendData(entity).ExecuteInserted();
|
||||
case DataType.MySql:
|
||||
case DataType.Oracle:
|
||||
case DataType.Sqlite:
|
||||
default:
|
||||
throw new NotImplementedException($"{_fsql.Ado.DataType}不支持类似returning或output类型的特性,请参考FreeSql插入数据的方法重新现实。");
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(TEntity entity) => _fsql.Update<TEntity>().SetSource(entity).ExecuteAffrows();
|
||||
async public virtual Task<TEntity> InsertAsync(TEntity entity) {
|
||||
switch (_fsql.Ado.DataType) {
|
||||
case DataType.SqlServer:
|
||||
case DataType.PostgreSQL:
|
||||
return (await _fsql.Insert<TEntity>().AppendData(entity).ExecuteInsertedAsync()).FirstOrDefault();
|
||||
case DataType.MySql:
|
||||
case DataType.Oracle:
|
||||
case DataType.Sqlite:
|
||||
default:
|
||||
throw new NotImplementedException($"{_fsql.Ado.DataType}不支持类似returning或output类型的特性,请参考FreeSql插入数据的方法重新现实。");
|
||||
}
|
||||
}
|
||||
|
||||
public Task UpdateAsync(TEntity entity) => _fsql.Update<TEntity>().SetSource(entity).ExecuteAffrowsAsync();
|
||||
public virtual Task<List<TEntity>> InsertAsync(List<TEntity> entity) {
|
||||
switch (_fsql.Ado.DataType) {
|
||||
case DataType.SqlServer:
|
||||
case DataType.PostgreSQL:
|
||||
return _fsql.Insert<TEntity>().AppendData(entity).ExecuteInsertedAsync();
|
||||
case DataType.MySql:
|
||||
case DataType.Oracle:
|
||||
case DataType.Sqlite:
|
||||
default:
|
||||
throw new NotImplementedException($"{_fsql.Ado.DataType}不支持类似returning或output类型的特性,请参考FreeSql插入数据的方法重新现实。");
|
||||
}
|
||||
}
|
||||
|
||||
public int Update(TEntity entity) => _fsql.Update<TEntity>().SetSource(entity).ExecuteAffrows();
|
||||
|
||||
public Task<int> UpdateAsync(TEntity entity) => _fsql.Update<TEntity>().SetSource(entity).ExecuteAffrowsAsync();
|
||||
}
|
||||
|
||||
public abstract class BaseRepository<TEntity, TKey> : BaseRepository<TEntity>, IRepository<TEntity, TKey>
|
||||
@ -41,9 +90,9 @@ namespace FreeSql {
|
||||
public BaseRepository(IFreeSql fsql) : base(fsql) {
|
||||
}
|
||||
|
||||
public void Delete(TKey id) => _fsql.Delete<TEntity>(id).ExecuteAffrows();
|
||||
public int Delete(TKey id) => _fsql.Delete<TEntity>(id).ExecuteAffrows();
|
||||
|
||||
public Task DeleteAsync(TKey id) => _fsql.Delete<TEntity>(id).ExecuteAffrowsAsync();
|
||||
public Task<int> DeleteAsync(TKey id) => _fsql.Delete<TEntity>(id).ExecuteAffrowsAsync();
|
||||
|
||||
public TEntity Find(TKey id) => _fsql.Select<TEntity>(id).ToOne();
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.1.2</Version>
|
||||
<Version>0.1.3</Version>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
|
||||
<Description>FreeSql 通用仓库层现实,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
|
||||
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
||||
<PackageTags>FreeSql ORM Repository</PackageTags>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
|
@ -1,28 +1,33 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql {
|
||||
public interface IBasicRepository<TEntity> : IReadOnlyRepository<TEntity>
|
||||
where TEntity : class {
|
||||
TEntity Insert(TEntity entity);
|
||||
|
||||
List<TEntity> Insert(List<TEntity> entity);
|
||||
|
||||
Task<TEntity> InsertAsync(TEntity entity);
|
||||
|
||||
void Update(TEntity entity);
|
||||
Task<List<TEntity>> InsertAsync(List<TEntity> entity);
|
||||
|
||||
Task UpdateAsync(TEntity entity);
|
||||
int Update(TEntity entity);
|
||||
|
||||
Task<int> UpdateAsync(TEntity entity);
|
||||
|
||||
IUpdate<TEntity> UpdateDiy { get; }
|
||||
|
||||
void Delete(TEntity entity);
|
||||
int Delete(TEntity entity);
|
||||
|
||||
Task DeleteAsync(TEntity entity);
|
||||
Task<int> DeleteAsync(TEntity entity);
|
||||
}
|
||||
|
||||
public interface IBasicRepository<TEntity, TKey> : IBasicRepository<TEntity>, IReadOnlyRepository<TEntity, TKey>
|
||||
where TEntity : class {
|
||||
void Delete(TKey id);
|
||||
int Delete(TKey id);
|
||||
|
||||
Task DeleteAsync(TKey id);
|
||||
Task<int> DeleteAsync(TKey id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,9 @@ namespace FreeSql {
|
||||
|
||||
public interface IRepository<TEntity> : IReadOnlyRepository<TEntity>, IBasicRepository<TEntity>
|
||||
where TEntity : class {
|
||||
void Delete(Expression<Func<TEntity, bool>> predicate);
|
||||
int Delete(Expression<Func<TEntity, bool>> predicate);
|
||||
|
||||
Task DeleteAsync(Expression<Func<TEntity, bool>> predicate);
|
||||
Task<int> DeleteAsync(Expression<Func<TEntity, bool>> predicate);
|
||||
}
|
||||
|
||||
public interface IRepository<TEntity, TKey> : IRepository<TEntity>, IReadOnlyRepository<TEntity, TKey>, IBasicRepository<TEntity, TKey>
|
||||
|
Reference in New Issue
Block a user