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 ...
随机推荐
- Hadoop —— 集群环境搭建
一.集群规划 这里搭建一个3节点的Hadoop集群,其中三台主机均部署DataNode和NodeManager服务,但只有hadoop001上部署NameNode和ResourceManager服务. ...
- ES6_05_三点运算符和形参默认值
三点运算符的用途: # 1. rest(可变)参数 * 用来取代arguments 但比 arguments 灵活,只能是最后部分形参参数 function fun(...values) { cons ...
- header 无法实现跳转
错误:Warning: Cannot modify header information - headers already sent by (output started at 方法:“php.in ...
- kafka迁移topic
1. 准备移动 这里假设要移动的topic名称为:topicA.topicB vim topics-to-move.json {"topics": [{"topic&qu ...
- 设计模式-桥接模式(Bridge)
桥接模式是构造型模式之一.把抽象(Abstraction)与行为实现(Implementor)分离开来,从而可以保持各部分的独立性以及应对它们的功能扩展. 角色和职责: 1.抽象类(Abstracti ...
- Python入门(一) 异常处理
异常处理 捕捉异常可以使用try/except语句. try/except语句用来检测try语句块中的错误,从而让except语句捕获异常信息并处理. 以下是语法: try: <语句> # ...
- Codeforces Gym101246J:Buoys(三分搜索)
http://codeforces.com/gym/101246/problem/J 题意:给出n个点坐标,要使这些点间距相同的话,就要移动这些点,问最少的需要的移动距离是多少,并输出移动后的坐标. ...
- HDU 3068:最长回文(Manacher算法)
http://acm.hdu.edu.cn/showproblem.php?pid=3068 最长回文 Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的 ...
- Linux部署项目常用命令
前言:一般项目都会使用阿里云等服务器作为云服务器.此时必不可免会使用到一系列常用的命令.这里我整合一下常用的命令 1.一般链接阿里云服务器常用的的是xshell跟xftp. 下载路径:https:// ...
- spring springMVC Struts2 区别
Spring: Spring是IOC和AOP的容器框架,Spring是一个通用解决方案, 最大的用处就是通过Ioc/AOP解耦, 降低软件复杂性, 所以Spring可以结合SpringMVC等很多其他 ...