素材巴巴 > 程序开发 >

WebApi(三)

程序开发 2023-09-06 06:04:11

使用webapi访问数据库

自定义接口
1.创建实体类

namespace Server.Models
 {public class ProductEntity:DbContext{public DbSet products { get; set; }}
 }
 

2.创建dal层

 public class productDal{ProductEntity entity = new ProductEntity();public List Getallproduct() {return entity.products.ToList();}}
 

3.创建bill层

public class productbill{productDal dal = new productDal();public List Getallproduct(){return dal.Getallproduct();}}
 

4.创建控制器

  public class ProductController : ApiController{productbill bill = new productbill();public List Getallproduct(){return bill.Getallproduct();}}
 

5.修改web.config
在这里插入图片描述
6.测试

在这里插入图片描述
完成!


标签:

素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。