WPF实战学习笔记09-创建工作单元

创建工作单元

添加包

  • 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.

依赖注入

image-20230712142942894

添加命名空间using Arch.EntityFrameworkCore.UnitOfWork;

添加仓储段

添加文件

  • webapi工程

./Repository/MemoRepository.cs

./Repository/ToDoRepository.cs

./Repository/UserRepository.cs

实现仓储段接口

注意要继承Repository, IRepository两个以及接口

MemoRepository.cs
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<MyTodoContext>, IRepository<Memo>
    {
        public MemoRepository(MyTodoContext dbContext) : base(dbContext)
        {
        }

        public int Count(Expression<Func<Memo, bool>> 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<Memo> entities)
        {
            throw new NotImplementedException();
        }

        public Memo GetFirstOrDefault(Expression<Func<Memo, bool>> predicate = null, Func<IQueryable<Memo>, IOrderedQueryable<Memo>> orderBy = null, Func<IQueryable<Memo>, IIncludableQueryable<Memo, object>> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public TResult GetFirstOrDefault<TResult>(Expression<Func<Memo, TResult>> selector, Expression<Func<Memo, bool>> predicate = null, Func<IQueryable<Memo>, IOrderedQueryable<Memo>> orderBy = null, Func<IQueryable<Memo>, IIncludableQueryable<Memo, object>> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public Task<TResult> GetFirstOrDefaultAsync<TResult>(Expression<Func<Memo, TResult>> selector, Expression<Func<Memo, bool>> predicate = null, Func<IQueryable<Memo>, IOrderedQueryable<Memo>> orderBy = null, Func<IQueryable<Memo>, IIncludableQueryable<Memo, object>> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public Task<Memo> GetFirstOrDefaultAsync(Expression<Func<Memo, bool>> predicate = null, Func<IQueryable<Memo>, IOrderedQueryable<Memo>> orderBy = null, Func<IQueryable<Memo>, IIncludableQueryable<Memo, object>> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public IPagedList<Memo> GetPagedList(Expression<Func<Memo, bool>> predicate = null, Func<IQueryable<Memo>, IOrderedQueryable<Memo>> orderBy = null, Func<IQueryable<Memo>, IIncludableQueryable<Memo, object>> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public IPagedList<TResult> GetPagedList<TResult>(Expression<Func<Memo, TResult>> selector, Expression<Func<Memo, bool>> predicate = null, Func<IQueryable<Memo>, IOrderedQueryable<Memo>> orderBy = null, Func<IQueryable<Memo>, IIncludableQueryable<Memo, object>> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, bool ignoreQueryFilters = false) where TResult : class
        {
            throw new NotImplementedException();
        }

        public Task<IPagedList<Memo>> GetPagedListAsync(Expression<Func<Memo, bool>> predicate = null, Func<IQueryable<Memo>, IOrderedQueryable<Memo>> orderBy = null, Func<IQueryable<Memo>, IIncludableQueryable<Memo, object>> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, CancellationToken cancellationToken = default, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public Task<IPagedList<TResult>> GetPagedListAsync<TResult>(Expression<Func<Memo, TResult>> selector, Expression<Func<Memo, bool>> predicate = null, Func<IQueryable<Memo>, IOrderedQueryable<Memo>> orderBy = null, Func<IQueryable<Memo>, IIncludableQueryable<Memo, object>> 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<Memo> entities)
        {
            throw new NotImplementedException();
        }

        public ValueTask<EntityEntry<Memo>> InsertAsync(Memo entity, CancellationToken cancellationToken = default)
        {
            throw new NotImplementedException();
        }

        public Task InsertAsync(params Memo[] entities)
        {
            throw new NotImplementedException();
        }

        public Task InsertAsync(IEnumerable<Memo> 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<Memo> entities)
        {
            throw new NotImplementedException();
        }

        Memo IRepository<Memo>.Find(params object[] keyValues)
        {
            throw new NotImplementedException();
        }

        ValueTask<Memo> IRepository<Memo>.FindAsync(params object[] keyValues)
        {
            throw new NotImplementedException();
        }

        ValueTask<Memo> IRepository<Memo>.FindAsync(object[] keyValues, CancellationToken cancellationToken)
        {
            throw new NotImplementedException();
        }

        IQueryable<Memo> IRepository<Memo>.FromSql(string sql, params object[] parameters)
        {
            throw new NotImplementedException();
        }

        IQueryable<Memo> IRepository<Memo>.GetAll()
        {
            throw new NotImplementedException();
        }
    }
}

ToDoRepository.cs
using Arch.EntityFrameworkCore.UnitOfWork;
using Microsoft.EntityFrameworkCore;
using MyToDo.Api.Context;

namespace MyToDo.Api.Repository
{
    public class ToDoRepository : Repository<Todo>, IRepository<Todo>
    {
        public ToDoRepository(MyTodoContext dbContext) : base(dbContext)
        {
        }
    }
}

User
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<MyTodoContext>, IRepository<User>
    {
        public UserRepository(MyTodoContext dbContext) : base(dbContext)
        {
        }

        public int Count(Expression<Func<User, bool>> 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<User> entities)
        {
            throw new NotImplementedException();
        }

        public User GetFirstOrDefault(Expression<Func<User, bool>> predicate = null, Func<IQueryable<User>, IOrderedQueryable<User>> orderBy = null, Func<IQueryable<User>, IIncludableQueryable<User, object>> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public TResult GetFirstOrDefault<TResult>(Expression<Func<User, TResult>> selector, Expression<Func<User, bool>> predicate = null, Func<IQueryable<User>, IOrderedQueryable<User>> orderBy = null, Func<IQueryable<User>, IIncludableQueryable<User, object>> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public Task<TResult> GetFirstOrDefaultAsync<TResult>(Expression<Func<User, TResult>> selector, Expression<Func<User, bool>> predicate = null, Func<IQueryable<User>, IOrderedQueryable<User>> orderBy = null, Func<IQueryable<User>, IIncludableQueryable<User, object>> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public Task<User> GetFirstOrDefaultAsync(Expression<Func<User, bool>> predicate = null, Func<IQueryable<User>, IOrderedQueryable<User>> orderBy = null, Func<IQueryable<User>, IIncludableQueryable<User, object>> include = null, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public IPagedList<User> GetPagedList(Expression<Func<User, bool>> predicate = null, Func<IQueryable<User>, IOrderedQueryable<User>> orderBy = null, Func<IQueryable<User>, IIncludableQueryable<User, object>> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public IPagedList<TResult> GetPagedList<TResult>(Expression<Func<User, TResult>> selector, Expression<Func<User, bool>> predicate = null, Func<IQueryable<User>, IOrderedQueryable<User>> orderBy = null, Func<IQueryable<User>, IIncludableQueryable<User, object>> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, bool ignoreQueryFilters = false) where TResult : class
        {
            throw new NotImplementedException();
        }

        public Task<IPagedList<User>> GetPagedListAsync(Expression<Func<User, bool>> predicate = null, Func<IQueryable<User>, IOrderedQueryable<User>> orderBy = null, Func<IQueryable<User>, IIncludableQueryable<User, object>> include = null, int pageIndex = 0, int pageSize = 20, bool disableTracking = true, CancellationToken cancellationToken = default, bool ignoreQueryFilters = false)
        {
            throw new NotImplementedException();
        }

        public Task<IPagedList<TResult>> GetPagedListAsync<TResult>(Expression<Func<User, TResult>> selector, Expression<Func<User, bool>> predicate = null, Func<IQueryable<User>, IOrderedQueryable<User>> orderBy = null, Func<IQueryable<User>, IIncludableQueryable<User, object>> 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<User> entities)
        {
            throw new NotImplementedException();
        }

        public ValueTask<EntityEntry<User>> InsertAsync(User entity, CancellationToken cancellationToken = default)
        {
            throw new NotImplementedException();
        }

        public Task InsertAsync(params User[] entities)
        {
            throw new NotImplementedException();
        }

        public Task InsertAsync(IEnumerable<User> 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<User> entities)
        {
            throw new NotImplementedException();
        }

        User IRepository<User>.Find(params object[] keyValues)
        {
            throw new NotImplementedException();
        }

        ValueTask<User> IRepository<User>.FindAsync(params object[] keyValues)
        {
            throw new NotImplementedException();
        }

        ValueTask<User> IRepository<User>.FindAsync(object[] keyValues, CancellationToken cancellationToken)
        {
            throw new NotImplementedException();
        }

        IQueryable<User> IRepository<User>.FromSql(string sql, params object[] parameters)
        {
            throw new NotImplementedException();
        }

        IQueryable<User> IRepository<User>.GetAll()
        {
            throw new NotImplementedException();
        }
    }
}

添加测试数据

1. 数据库添加测试数据

2. 编写测试程序

  • WeatherForecastController(覆盖到对应的类中)

    private readonly IUnitOfWork uow;
    
    public WeatherForecastController(ILogger<WeatherForecastController> logger,IUnitOfWork unitOfWork)
    {
        _logger = logger;
        this.uow = unitOfWork;
    }
    public IEnumerable<WeatherForecast> Get()
    {
        //获取用户表
        var service= uow.GetRepository<User>();
        var res = service.GetAll();
        var rng = new Random();
    }
    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/44096.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Python实战项目——旅游数据分析(四)

由于有之前的项目&#xff0c;所以今天我们直接开始&#xff0c;不做需求分析&#xff0c;还不会需求分析的可以看我之前的文章。Python实战项目——用户消费行为数据分析&#xff08;三&#xff09; 导入库 import numpy as np import pandas as pd import matplotlib.pyplo…

Canal深入调研

Canal深入调研 1.canal的设计 1.1 Canal的设计理念 canal的组件化设计非常好&#xff0c;有点类似于tomcat的设计。使用组合设计&#xff0c;依赖倒置&#xff0c;面向接口的设计。 说明&#xff1a; ​ server代表一个canal运行实例&#xff0c;对应于一个jvm ​ instance…

elasticsearch操作(命令方式)

说明&#xff1a;elasticsearch是目前最流行的搜索引擎&#xff0c;功能强大&#xff0c;非常受欢迎。特点是倒排索引&#xff0c;在海量数据的模糊查找领域&#xff0c;效率非常高。elasticsearch的安装和使用参考&#xff1a;http://t.csdn.cn/yJdZb。 本文介绍在es的索引库…

ajax/axios访问后端测试方法

文章目录 1、浏览器执行javascript方法GET请求POST请求 2、Postman测试工具GET请求POST请求 3、idea IDE提供的httpclient4、Apache JMeter 1、浏览器执行javascript方法 GET请求 http://localhost:6060/admin/get/123 POST请求 技巧&#xff1a;打开谷歌浏览器&#xff0c…

隧道安全监测解决方案

隧道安全监测 解决方案 一、监测目的 通过监控量测&#xff0c;实现信息化施工&#xff0c;不仅能及时掌握隧道实际的地质情况&#xff0c;掌握隧道围岩、支护衬砌结构的受力特征和变形情况&#xff0c;据此可以尽早发现塌方、大变形等灾害征兆&#xff0c;及时采取措施&…

使用ffmpeg合并视频遇到的坑

下面以Linux环境介绍为主 1.ffmpeg可执行命令不同的环境是不同的&#xff0c;Linux在执行命令前还需要授权。 2.合并视频命令&#xff1a; 主要命令: {} -f concat -auto_convert 0 -safe 0 -i {} -y -c:v copy 坑一&#xff1a;其中第一个花括号替换的是可执行命令所在的…

elementui全局给select option添加title属性

场景 有天边上的同事问了我一个问题&#xff0c;示例如下&#xff0c;有个数据特别长&#xff0c;导致下拉部分被横向撑大。希望在全局对所有的option进行处理&#xff0c;按照select的宽度&#xff0c;超出隐藏。 处理 方式一 第一眼看过去直接修改源码好了&#xff0c;修…

权智A133P 安卓10移植SPI转串WK2124驱动

硬件连接示意图 主控CPU通过SPI总线与WK2XXX芯相连接。WK2XXX控制4个UART的数据收发。 其中重要的参数有CS片选线和IRQ中断引脚。 LInux串口驱动框架 当WK2XXX驱动在内核注册成功后&#xff0c;会在/dev目录下面生成ttysWK0,ttysWK1,ttysWK2,ttysWK3节点。上层通过open,read,w…

精通正则表达式 - 打造高效正则表达式

目录 一、典型示例 1. 稍加修改——先迈最好使的腿 2. 效率 vs 准确性 3. 继续前进——限制匹配优先的作用范围 4. “指数级”匹配 二、全面考察回溯 1. 传统 NFA 的匹配过程 2. POSIX NFA 需要更多处理 3. 无法匹配时必须进行的工作 4. 看清楚一点 5. 多选结构的代…

Spring Boot日志:SLF4J和Logback

日志的分类 SpringBoot中的日志库分为两种&#xff1a; 实现库&#xff1a;提供具体的日志实现&#xff0c;例如日志级别的控制、打印格式、输出目标等。外观库&#xff1a;自身不提供日志实现&#xff0c;而是对其他日志库进行封装&#xff0c;从而方便使用。基于外观模式实…

Redis实战案例24-关注推送

1. Feed流实现方案 拉模式主要缺点&#xff0c;延迟问题&#xff0c;极端情况某个用户关注了成千上万的up主&#xff0c;每位up主又发布了十几条博客&#xff0c;此时拉模式的延迟就会很高&#xff1b; 推模式缺点也很明显&#xff0c;内存消耗太大&#xff0c;假设up主是千万级…

网络安全 Day20-计算机网络基础知识05(网络原理)

计算机网络基础知识05&#xff08;网络原理&#xff09; 1. OSI 模型2. VMware虚拟机NAT模式下上网原理3. 不能上网故障排查 1. OSI 模型 OSI 7层网络通信原理模型 OSI 国际网互联 OSI 数据包封装解封装过程 北京局域网主机A到深圳局域网主机B数据工作流程 2. VMware虚拟机N…

《零基础入门学习Python》第066讲:GUI的终极选择:Tkinter3

今天我们一起来学习三个组件&#xff1a;Checkbutton、Radiobutton 和 LabelFrame。 同样&#xff0c;我们还是通过案例来讲解。 一、Checkbutton Checkbutton&#xff08;多选框&#xff09;。大家都知道什么叫做“翻牌子”&#xff0c;今天的第一个例子就是来写一个翻牌子…

巅峰极客2023 hellosql

随便输一个payload&#xff0c;有waf 这题只有两个回显&#xff0c;分别是太酷啦和nonono&#xff0c;不显示报错、登录成功等各种信息&#xff0c;目前只能想到用时间盲注。 抓包fuzz&#xff0c;194都是被过滤的 不止这些&#xff0c;手工测出来if、sleep、benchmark、*、rp…

opencv-20 深入理解HSV 色彩空间(通过指定,标记颜色等来拓展ROI区域)

RGB 色彩空间是一种被广泛接受的色彩空间&#xff0c;但是该色彩空间过于抽象&#xff0c;我们不能够直接通过其值感知具体的色彩。 我们更习惯使用直观的方式来感知颜色&#xff0c;HSV 色彩空间提供了这样 的方式。 通过 HSV色彩空间&#xff0c;我们能够更加方便地通过色调、…

Keil系列教程08_Configuration(二)

1写在前面 本文接着上一篇文章《Keil系列教程07_Configuration&#xff08;一&#xff09;》讲述的工程目标选项的后三项配置&#xff1a;Shortcut Keys快捷键、Text Completion代码完形、Other其他。 这后面三部分内容在该系列教程其它也会牵涉&#xff0c;也是一些常用、重要…

idea中常用的快捷键

快捷键: 1.快速生成main方法 main/psvm public static void main(String[] args) {} 2.快速复制当前行的代码: ctrld 3.快速捕获异常: altctrlt 4.快速打印结果: sout/soutv System.out.println(s); System.out.println("s " s); 5.自动生成对象的返回值…

tinkerCAD案例:8.Cylinder Earrings 圆筒耳环

tinkerCAD案例&#xff1a;8.Cylinder Earrings 圆筒耳环 In this lesson you will learn how to create earrings using cylinder shapes. So let’s get started! 在本课中&#xff0c;您将学习如何使用圆柱形制作耳环。所以让我们开始吧&#xff01; 说明 Drag a Cylinder …

el-Cascader 中div上绑定keyDown事件

keydown&#xff0c;keyup&#xff0c;keypress 事件默认是给页面上可以聚焦的元素绑定键盘事件&#xff0c;例如input输入框&#xff0c;点击输入框即代表聚焦在该元素上。那么想要给div或者其他不能聚焦的元素上使用键盘事件怎么处理呢&#xff1f;这里用到tabindex属性。 …

SWF格式视频怎么转换成AVI格式?简单的转换方法分享

当你想要在不同的设备上播放视频时&#xff0c;将SWF格式视频转换成AVI格式是非常有用的。因为SWF格式通常只能在特定的软件或网页上播放&#xff0c;而AVI格式则可以在更广泛的设备上播放&#xff0c;包括智能手机&#xff0c;平板电脑和电视机等。那么我们怎么将SWF转换成AVI…