src/Czar.Cms.Core/Repository/UnitOfWork.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/**
*┌──────────────────────────────────────────────────────────────┐
*│ 描 述:工作单元实现类
*│ 作 者:yilezhu
*│ 版 本:1.0
*│ 创建时间:2018/12/22 19:52:12
*└──────────────────────────────────────────────────────────────┘
*┌──────────────────────────────────────────────────────────────┐
*│ 命名空间: Czar.Cms.Core.Repository
*│ 类 名: UnitOfWork
*└──────────────────────────────────────────────────────────────┘
*/
using Czar.Cms.Core.DbHelper;
using Czar.Cms.Core.Options;
using Dapper;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Transactions;
namespace Czar.Cms.Core.Repository
{
public class UnitOfWork : IUnitOfWork
{
public IDbConnection _dbConnection;
protected DbOption _dbOpion;
private Dictionary<object, Action> addEntities;
private Dictionary<object, Action> updateEntities;
private Dictionary<object, Action> deleteEntities;
public UnitOfWork(IOptionsSnapshot<DbOption> options)
{
_dbOpion = options.Get("CzarCms");
if (_dbOpion == null)
{
throw new ArgumentNullException(nameof(DbOption));
}
addEntities = new Dictionary<object, Action>();
updateEntities = new Dictionary<object, Action>();
deleteEntities = new Dictionary<object, Action>();
}
public void Add<TEntity>(TEntity entity) where TEntity : class
{
this.addEntities.Add(entity, () =>
{
_dbConnection.Insert<TEntity>(entity);
});
}
public void Update<TEntity>(TEntity entity) where TEntity : class
{
this.updateEntities.Add(entity, () =>
{
_dbConnection.Update(entity);
});
}
后面还有 69 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
