abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十一)
abp(net core)+easyui+efcore实现仓储管理系统目录
abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一)
abp(net core)+easyui+efcore实现仓储管理系统——解决方案介绍(二)
abp(net core)+easyui+efcore实现仓储管理系统——领域层创建实体(三)
abp(net core)+easyui+efcore实现仓储管理系统——定义仓储并实现 (四)
abp(net core)+easyui+efcore实现仓储管理系统——创建应用服务(五)
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之控制器(六)
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之列表视图(七)
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之增删改视图(八)
abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之菜单与测试(九)
abp(net core)+easyui+efcore实现仓储管理系统——多语言(十)
通过abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之控制器(六)至abp(net core)+easyui+efcore实现仓储管理系统——展现层实现增删改查之菜单与测试(九)四篇文章的学习,我们使用ASP.NET Core Mvc的常规的实现方式实现了对数据库的CURD操作。ABP有其默认的实现增删改查的方式。我们可以先看一下“ABP.TPLMS.Web.Mvc”项目中的“Views\Users”的相关代码,可以查看一下ABP默认是如何实现对用户信息的增删改查的。我们发现ABP中的用户信息的增删改查是通过继承 AsyncCrudAppService这个类来实现CURD操作,前端页面中通过javascript调用WEB API来实现增删改查。当然还有一个同步操作类CrudAppService,通过继承这个类来实现CURD的同步操作。对于这两个类的的区别在于AsyncCrudAppService是CrudAppService异步实现。ABP作为开发框架,通过以上两个基类实现了对于CRUD这种通用功能的一种解决方案。在接下来的几篇文章中,我们要通过继承 AsyncCrudAppService这个类来实现CURD操作,在前端通过调用WebAPI来实现对供应商信息的增删改查功能。
先来看一下AsyncCrudAppService与CrudAppService这两个类具体提供的功能。
首先,这两个类都继承自CrudAppServiceBase类。如图1,图2。

图1

图2
其次,这两个类都提供了Create、Delete、Update、Get、GetAll、GetEntityById方法。
第三,CrudAppServiceBase类提供了有关于权限(xxxPermissionName属性和CheckxxxPermission方法)的属性和方法,关于分页(ApplyPaging)的方法,关于排序(ApplySorting)方法,关于查询条件(CreateFilteredQuery)的方法,关于对象映射(MapToxxx)的方法。如下图。 
接下来我们来通过实现一个供应商信息的管理功能来学习一下这种方式实现增删改查功能。我会通过几篇文章来一步一步来实现这个供应商管理的功能。
一、创建Supplier实体
1. 在Visual Studio 2017的“解决方案资源管理器”中,右键单击“ABP.TPLMS.Core”项目的“Entitys”文件夹,在弹出菜单中选择“添加” --> “类”。 将类命名为 Supplier,然后选择“添加”。
2.创建Supplier类继承自Entity<int>,通过实现审计模块中的IHasCreationTime来实现保存创建时间。代码如下:
using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using Abp.Timing;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text; namespace ABP.TPLMS.Entitys
{
public class Supplier : Entity<int>, IHasCreationTime
{
public const int MaxLength = ;
public Supplier()
{ this.Address = string.Empty;
this.Name = string.Empty;
this.Email = string.Empty;
this.Code = string.Empty; this.Sex = ;
this.LinkName = string.Empty;
this.Status = ;
this.Tel = string.Empty;
this.Mobile = string.Empty;
this.UserId = ; CreationTime = Clock.Now;
} [Required]
[StringLength()]
public string Code { get; set; } [Required]
[StringLength(MaxLength)]
public string Name { get; set; } [StringLength(MaxLength)]
public string Address { get; set; } [Required]
[StringLength(MaxLength)] public string Email { get; set; } [StringLength(MaxLength)]
public string LinkName { get; set; }
public int Sex { get; set; } [Required]
[StringLength(MaxLength)]
public string Tel { get; set; }
[StringLength(MaxLength)]
public string Mobile { get; set; }
public int Status { get; set; }
public int UserId { get; set; }
public DateTime CreationTime { get; set; }
}
}
3.定义好实体之后,我们去“ABP.TPLMS.EntityFrameworkCore”项目中的“TPLMSDbContext”类中定义实体对应的DbSet,以应用Code First 数据迁移。添加以下代码
using Microsoft.EntityFrameworkCore;
using Abp.Zero.EntityFrameworkCore;
using ABP.TPLMS.Authorization.Roles;
using ABP.TPLMS.Authorization.Users;
using ABP.TPLMS.MultiTenancy;
using ABP.TPLMS.Entitys; namespace ABP.TPLMS.EntityFrameworkCore
{
public class TPLMSDbContext : AbpZeroDbContext<Tenant, Role, User, TPLMSDbContext>
{
/* Define a DbSet for each entity of the application */ public TPLMSDbContext(DbContextOptions<TPLMSDbContext> options)
: base(options) {
} public DbSet<Module> Modules { get; set; }
public DbSet<Supplier> Suppliers { get; set; }
}
}
4.从菜单中选择“工具->NuGet包管理器器—>程序包管理器控制台”菜单。
5. 在PMC中,默认项目选择EntityframeworkCore对应的项目后。输入以下命令:Add-Migration AddEntitySupplier,创建迁移。如下图。

6. 在上面的命令执行完毕之后,创建成功后,会在Migrations文件夹下创建时间_AddEntitySupplier格式的类文件,这些代码是基于DbContext指定的模型。如下图。

7.在程序包管理器控制台,输入Update-Database,回车执行迁移。如下图。

8.执行成功后,查看数据库,Suppliers表创建成功。

abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十一)的更多相关文章
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十二)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十三)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十四)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十五)
core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+easyui+e ...
- abp(net core)+easyui+efcore实现仓储管理系统——入库管理之五(四十一)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统——出库管理之三(五十一)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统--ABP总体介绍(一) abp(net core)+ ...
- abp(net core)+easyui+efcore实现仓储管理系统——菜单 (十六)
系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+easyui+efcore实现仓储管理系统——解决方案介绍(二) ...
- abp(net core)+easyui+efcore实现仓储管理系统——菜单-下(十七)
实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+easyui+efcore实现仓储管理系统——解决方案 ...
- abp(net core)+easyui+efcore实现仓储管理系统——EasyUI前端页面框架 (十八)
目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+easyui+efcore实现仓储管理系统——解决方案介绍(二) ab ...
随机推荐
- Google Earth Engine城市水体提取
Google Earth Engine城市水体提取 大家都知道城市水体提取相比较于山区,丘陵的地区,肯定是比较难的,为什么呢,因为城市水体有很多高层建筑导致的阴影,这个就非常复杂了,而且现在很多高分影 ...
- python trojan development 2nd —— use python to send mail and listen to the key board then combine them
请勿用于非法用途!!!!!本人概不负责!!!原创作品,转载说明出处!!!!! from pynput.keyboard import Key,Listener import logging impor ...
- 在C#中用静态类来扩展类的方法
目录 在C#中用静态类来扩展类的方法 1.待扩展类 2.用于扩展的静态类中的静态方法 3 静态扩展方法的调用 4 适用场景 在C#中用静态类来扩展类的方法 1.待扩展类 private IList&l ...
- 前端Vue基础学习
Vue基础 对与vue的简洁明了的干货分享,适合小白学习观看,如果有笔误或者想了解更多的,请给笔者留言,后续会继续分享,从零开始的vue相关经验 1.创建vue实例 <div id=" ...
- Log2Net日志查询网站代码解析
在前面的几节中,我们介绍了Log2Net的使用方法和代码设计.使用这个组件,我们可以方便地将日志记录到数据库中,那么,我们怎么能看到这些日志呢?于是,日志查询网站应运而生.效果图如下: 该代码已开源, ...
- HttpUtility.UrlEncode讲解
hello 大家好,今天讲讲HttpUtility.UrlEncode编码 HttpUtility.UrlEncode方法有4个重载分别如下 我们有这么一个字符串 string str = " ...
- 为什么Java只有值传递?
形参和实参 形式参数,是在方法定义阶段,是定义某个函数时使用的参数,用于接收实参传入.例f(x,y)中x和y是形参. 实际参数,是在方法调用阶段,是主调函数调用有参函数时,实际传递的内容.例f(3,7 ...
- 浅入深出Vue:第一个页面
今天正式开始入门篇,也就是实战了~ 首先我们是要做一个博客网站,UI 框架采用江湖传闻中的 ElementUI,今天我们就来利用它确定我们博客网站的基本布局吧. 准备工作 新建一个vue项目(可以参考 ...
- JPA自定义实体的id
背景:继上一篇文章,已经实现客户端数据库数据,存入服务器,但是,两张表的id不一样,应该是id设置自增了,所以虽然从客户端查出的实体带id,但是存入服务器时id被抹掉,按照服务端表的id序号向上自增, ...
- nginx实战操作(常用命令及配置)
1. nginx介绍 2. nginx常用命令 验证配置是否正确: nginx -t 查看Nginx的详细的版本号:nginx -V 查看Nginx的简洁版本号:nginx -v 启动Nginx:st ...