第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

快速上手 ABP 框架學(xué)習(xí)筆記記錄(30天學(xué)習(xí)記錄)第四天

標(biāo)簽:
C#

ABP 在网上火了很久了,之前自己的有学习过一小段时间,但之后懒癌发作,就停止学习了。
人生啊,还真的要不断学习~由其是当编程人员!!!!
不说了,为了备忘,所以记录下一些比较重要的东西。

一个不错的ABP博客文:http://www.cnblogs.com/sheng-jie/p/6260035.html

写得很好的~而且有代码

代码完成后再上传

1.数据迁移

命令: update-database
       Add-Migration Add_yourEntityName_Entity

如果你在ABP 官网下载了DEMO(带ZERO),使用VS2017(以后可能20XX)打开,重新生成后,设置web项目下的WEB.CONFIG 数据库连接字符串后,可以使用以上两个代码生成数据库。

创建新的表(EF Code First)

在XXX.Core 领域项目下,新建类. (例如 School)

继承 ABP 中的 ENTITY 类, 该类有一个属性 Id , 默认为 INT 类型的,

但也可以修改为其他类型。

   demo : public class School :Entity<string>{   .....    }

创建完一个类,那么如何通过命令新增数据库呢?
Add-Migration Add_yourEntityName_Entity 命令就可以出场了。
(PS:
1.必须设置WEB 、WEB API 项目为启用项
2.在工具-》NuGet包管理器-》程序包管理控制台

如下图图片描述

PM> Add-Migration Add_yourEntityName_Entity

回车后,正常情况会在 Demo.EntityFramework 项目下生成一个以时间格式+类名 的文件

然后再使用

PM>Update DataBase 

这样数据库就会新建一张表


Application

Application 是 WEB 和 CODE 项目间的桥梁,

DTO

个人理解是:同一个表,在不同的页面,需要展示的属性是不同的。不多不少只展示需求暴露的属性就好了,DTO 就是不同的 视图类。
建不同的DTO 类有利于扩展和不会造成混乱。(这个简单说法不太能说明DTO的好处,不想在这里说太多了,在写比较复杂的页面时,就能体会到)

IXXXXService
代码如下: 创建一个接口并现实,然后在WEB 中就可以调用了。
那么数据库中的交互是怎样的呢?
(从官网下载的项目中: XXXX.EntityFramework中的文件夹EntityFramework 有一个文件:XXXXDbContext

新建一个类后在此页面中添加: DEMO如下

  public class DemoDbContext : AbpZeroDbContext<Tenant, Role, User>
    {
        //TODO: Define an IDbSet for your Entities...

            public IDbSet<Schools> School { get; set; }

            ......其他代码......
   }
 public interface ISchoolService : IApplicationService
    {
        void GetAll();
    }

public class SchoolService:ISchoolService
    {
        private readonly IRepository<Schools, string> _SchoolsRepository;

        public SchoolService(IRepository<Schools, string> schoolsRepository)
        {
            _SchoolsRepository = schoolsRepository;
        }

        public void GetAll()
        {
            var list = _SchoolsRepository.GetAll().ToList();
        }
    }

上述代码: 应该不难理解,要注意一点是: 如果在ABP中没有创建类的Repository (School 类就没有),则可以使用ABP框架中的Repository 的方法。如下图:
图片描述

写好这里,那么在WEB项目中 注入构造函数,即可以与数据库交互了。


Repositories

上面说到,如果ABP 提供的方法不能满足你的需求,那么这要自定义一个Repositories

新建Repositories 和实现 Repositories 在 CORE 和 EntityFramework 项目中

1.CORE 项目下的 IRepositories 文件夹 新建一个 IStudentRepository


   // Student 学习实体(不清楚,看上面)
   public interface IStudentRepository: IRepository<Student,string>
    {
        void GetStudentTest();
    }

2.EntityFramework 项目中实现新建的 IRepositories

EntityFramework -》EntityFramework-》Repositories文件夹

 public class StudentRepository:DemoRepositoryBase<Student,string>, IStudentRepository
    {
        public StudentRepository(IDbContextProvider<DemoDbContext> dbContextProvider):base(dbContextProvider)
        {

        }
        //获取学生信息
        public void GetStudentTest()
        {
            var query = GetAllList();
        }
    }

继承DemoRepositoryBase 并实现接口

编写完以上代码,那么要在 Application 项目中调用。

public class StudentService : IStudentService
    {

        //因为自定义了Repository,所以不用  IRepository<Schools, string> 
        private readonly IStudentRepository _StudentRepository;

        public StudentService(IStudentRepository studentRepository)
        {
            _StudentRepository = studentRepository;
        }

        //这个方法是 IStudentService 中定义的
        public void GetStudentTest()
        {
           //这个方法是在 IStudentRepository 中定义的
            _StudentRepository.GetStudentTest();
        }
    }

然后在WEB层就能调用,测试过,能获取到数据

坚持的第四天。

在剩余2017年里,每晚也要学习!!!

點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶(hù)
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消