Microsoft.EntityFrameworkCore.AutoHistory
A plugin for Microsoft.EntityFrameworkCore to support automatically recording data changes history.
Microsoft.EntityFrameworkCore.UnitOfWork
A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported.
添加命名空间using Arch.EntityFrameworkCore.UnitOfWork;
./Repository/MemoRepository.cs
./Repository/ToDoRepository.cs
./Repository/UserRepository.cs
注意要继承Repository, IRepository两个以及接口
using Arch.EntityFrameworkCore.UnitOfWork;
using Arch.EntityFrameworkCore.UnitOfWork.Collections;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Query;
using MyToDo.Api.Context;
using System.Linq.Expressions;
namespace MyToDo.Api.Repository
{
public class MemoRepository : Repository, IRepository
{
public MemoRepository(MyTodoContext dbContext) : base(dbContext)
{
}
public int Count(Expression> predicate = null)
{
throw new NotImplementedException();
}
public void Delete(Memo entity)
{
throw new NotImplementedException();
}
public void Delete(params Memo[] entities)
{
throw new NotImplementedException();
}
public void Delete(IEnumerable entities)
{
throw new NotImplementedException();
}
public Memo GetFirstOrDefault(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public TResult GetFirstOrDefault(Expression> selector, Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public Task GetFirstOrDefaultAsync(Expression> selector, Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public Task GetFirstOrDefaultAsync(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public IPagedList GetPagedList(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public IPagedList GetPagedList(Expression> selector, Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, bool ignoreQueryFilters = false) where TResult : class
{
throw new NotImplementedException();
}
public Task> GetPagedListAsync(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, CancellationToken cancellationToken = default, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public Task> GetPagedListAsync(Expression> selector, Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, CancellationToken cancellationToken = default, bool ignoreQueryFilters = false) where TResult : class
{
throw new NotImplementedException();
}
public void Insert(Memo entity)
{
throw new NotImplementedException();
}
public void Insert(params Memo[] entities)
{
throw new NotImplementedException();
}
public void Insert(IEnumerable entities)
{
throw new NotImplementedException();
}
public ValueTask> InsertAsync(Memo entity, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task InsertAsync(params Memo[] entities)
{
throw new NotImplementedException();
}
public Task InsertAsync(IEnumerable entities, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public void Update(Memo entity)
{
throw new NotImplementedException();
}
public void Update(params Memo[] entities)
{
throw new NotImplementedException();
}
public void Update(IEnumerable entities)
{
throw new NotImplementedException();
}
Memo IRepository.Find(params object[] keyValues)
{
throw new NotImplementedException();
}
ValueTask IRepository.FindAsync(params object[] keyValues)
{
throw new NotImplementedException();
}
ValueTask IRepository.FindAsync(object[] keyValues, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
IQueryable IRepository.FromSql(string sql, params object[] parameters)
{
throw new NotImplementedException();
}
IQueryable IRepository.GetAll()
{
throw new NotImplementedException();
}
}
}
using Arch.EntityFrameworkCore.UnitOfWork;
using Microsoft.EntityFrameworkCore;
using MyToDo.Api.Context;
namespace MyToDo.Api.Repository
{
public class ToDoRepository : Repository, IRepository
{
public ToDoRepository(MyTodoContext dbContext) : base(dbContext)
{
}
}
}
using Arch.EntityFrameworkCore.UnitOfWork;
using Arch.EntityFrameworkCore.UnitOfWork.Collections;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Query;
using MyToDo.Api.Context;
using MyToDo.Api.Migrations;
using System.Linq.Expressions;
namespace MyToDo.Api.Repository
{
public class UserRepository : Repository, IRepository
{
public UserRepository(MyTodoContext dbContext) : base(dbContext)
{
}
public int Count(Expression> predicate = null)
{
throw new NotImplementedException();
}
public void Delete(User entity)
{
throw new NotImplementedException();
}
public void Delete(params User[] entities)
{
throw new NotImplementedException();
}
public void Delete(IEnumerable entities)
{
throw new NotImplementedException();
}
public User GetFirstOrDefault(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public TResult GetFirstOrDefault(Expression> selector, Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public Task GetFirstOrDefaultAsync(Expression> selector, Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public Task GetFirstOrDefaultAsync(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public IPagedList GetPagedList(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public IPagedList GetPagedList(Expression> selector, Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, bool ignoreQueryFilters = false) where TResult : class
{
throw new NotImplementedException();
}
public Task> GetPagedListAsync(Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, CancellationToken cancellationToken = default, bool ignoreQueryFilters = false)
{
throw new NotImplementedException();
}
public Task> GetPagedListAsync(Expression> selector, Expression> predicate = null, Func, IOrderedQueryable> orderBy = null, Func, IIncludableQueryable> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, CancellationToken cancellationToken = default, bool ignoreQueryFilters = false) where TResult : class
{
throw new NotImplementedException();
}
public void Insert(User entity)
{
throw new NotImplementedException();
}
public void Insert(params User[] entities)
{
throw new NotImplementedException();
}
public void Insert(IEnumerable entities)
{
throw new NotImplementedException();
}
public ValueTask> InsertAsync(User entity, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task InsertAsync(params User[] entities)
{
throw new NotImplementedException();
}
public Task InsertAsync(IEnumerable entities, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public void Update(User entity)
{
throw new NotImplementedException();
}
public void Update(params User[] entities)
{
throw new NotImplementedException();
}
public void Update(IEnumerable entities)
{
throw new NotImplementedException();
}
User IRepository.Find(params object[] keyValues)
{
throw new NotImplementedException();
}
ValueTask IRepository.FindAsync(params object[] keyValues)
{
throw new NotImplementedException();
}
ValueTask IRepository.FindAsync(object[] keyValues, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
IQueryable IRepository.FromSql(string sql, params object[] parameters)
{
throw new NotImplementedException();
}
IQueryable IRepository.GetAll()
{
throw new NotImplementedException();
}
}
}
WeatherForecastController(覆盖到对应的类中)
private readonly IUnitOfWork uow;
public WeatherForecastController(ILogger logger,IUnitOfWork unitOfWork)
{
_logger = logger;
this.uow = unitOfWork;
}
public IEnumerable Get()
{
//获取用户表
var service= uow.GetRepository();
var res = service.GetAll();
var rng = new Random();
}