tnblog
首页
视频
资源
登录

.net Core From DataBase Layer To UI Layer

5507人阅读 2019/7/12 16:16 总访问:3467290 评论:2 收藏:0 手机
分类: .net后台框架

Here we have created the database.

OK,let's GO!

First:

You need create a new .net core to web application!

And create a .net core library

 


Then you need to see if EFcore, EFDesign, EFTools have been installed in the project configuration. If not, install the following commands through Nuget

  1. Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 2.2.6
  2. Install-Package Microsoft.EntityFrameworkCore.Design -Version 2.2.6
  3. Install-Package Microsoft.EntityFrameworkCore.Tools -Version 2.2.6
  4. //EFCore self-contained program .You Can Ctrl+/


With these

You can execute the following commands to automatically generate the entity model under the Model folder.

  1. Scaffold-DbContext "Server=.;database=bb;uid=sa;pwd=xxx" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

Ok! Now!

You can see that the physical model is built.

Then.

We need Create conntion string to appsettings.json ,like this!

  1. "ConnectionStrings": {
  2.     "BloggingDatabase""Server=.;database=bb;uid=sa;pwd=xxx"
  3.   },

Then we need DI   To startup.cs(ConfigureServices) 

  1. var connection = Configuration.GetConnectionString("BloggingDatabase");
  2. services.AddDbContextPool<INGoodsTrackerDBContext>(option =>
  3. {
  4.     if (!option.IsConfigured)
  5.     {
  6.         option.UseSqlServer(connection);
  7.     }
  8. });

I'm sure you're curious why I don't use the AddDbContext method here , but the AddDbContextPool method.

You can refer to this article recommended by my colleague Venzent.

  1. https://neelbhatt.com/2018/02/27/use-dbcontextpooling-to-improve-the-performance-net-core-2-1-feature/

I won't say much.

Let's continue.


  1. private LocalDBContext _Context { getset; }
  2.         public TestController(LocalDBContext Context)
  3.         {
  4.             _Context = Context;
  5.         }

After these completions ,we can finish it.

Becareful:  The OnConfiguring method in the generated content. CS needs to be removed when using dependency injection.


欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739

评价

剑轩

2019/8/22 10:15:02

c语言很厉害,各种东西都可以写

net core 使用 EF Code First

下面这些内容很老了看这篇:https://www.tnblog.net/aojiancc2/article/details/5365 项目使用多层,把数据库访问...

.net mvc分部页,.net core分部页

.net分部页的三种方式第一种:@Html.Partial(&quot;_分部页&quot;)第二种:@{ Html.RenderPartial(&quot;分部页&quot;);}...

StackExchange.Redis操作redis(net core支持)

官方git开源地址https://github.com/StackExchange/StackExchange.Redis官方文档在docs里边都是官方的文档通过nuget命令下...

.net core 使用session

tip:net core 2.2后可以直接启用session了,不用在自己添加一次session依赖,本身就添加了使用nuget添加引用Microsoft.AspN...

通俗易懂,什么是.net?什么是.net Framework?什么是.net core?

朋友圈@蓝羽 看到一篇文章写的太详细太通俗了,搬过来细细看完,保证你对.NET有个新的认识理解原文地址:https://www.cnblo...

asp.net core2.0 依赖注入 AddTransient与AddScoped的区别

asp.net core主要提供了三种依赖注入的方式其中AddTransient与AddSingleton比较好区别AddTransient瞬时模式:每次都获取一...

.net core 使用 Kestrel

Kestrel介绍 Kestrel是一个基于libuv的跨平台web服务器 在.net core项目中就可以不一定要发布在iis下面了Kestrel体验可以使...

net core中使用cookie

net core中可以使用传统的cookie也可以使用加密的cookieNET CORE中使用传统cookie设置:HttpContext.Response.Cookies.Appe...

net core项目结构简单分析

一:wwwrootwwwroot用于存放网站的静态资源,例如css,js,图片与相关的前端插件等lib主要是第三方的插件,例如微软默认引用...

net core使用EF之DB First

一.新建一个.net core的MVC项目新建好项目后,不能像以前一样直接在新建项中添加ef了,需要用命令在添加ef的依赖二.使用Nug...

.net core使用requestresponse下载文件下载excel等

使用request获取内容net core中request没有直接的索引方法,需要点里边的Query,或者formstringbase64=Request.Form[&quot;f...

iframe自适应高度与配合net core使用

去掉iframe边框frameborder=&quot;0&quot;去掉滚动条scrolling=&quot;no&quot;iframe 自适应高度如果内容是固定的,那么就...

net core启动报错Unable to configure HTTPS endpoint. No server certificate was specified

这是因为net core2.1默认使用的https,如果使用Kestrel web服务器的话没有安装证书就会报这个错其实仔细看他的错误提示,其...

net core中使用url编码与解码操作

net core中暂时还没有以前asp.net与mvc中的server对象。获取url的编码与解码操作不能使用以前的server对象来获取。使用的是...

下载net core

官方下载地址:https://dotnet.microsoft.com/download 进来之后就可以看到最新的下载版本可以直接点击下载,也可以下载其...
这一世以无限游戏为使命!
排名
2
文章
634
粉丝
44
评论
93
docker中Sware集群与service
尘叶心繁 : 想学呀!我教你呀
一个bug让程序员走上法庭 索赔金额达400亿日元
叼着奶瓶逛酒吧 : 所以说做程序员也要懂点法律知识
.net core 塑形资源
剑轩 : 收藏收藏
映射AutoMapper
剑轩 : 好是好,这个对效率影响大不大哇,效率高不高
ASP.NET Core 服务注册生命周期
剑轩 : http://www.tnblog.net/aojiancc2/article/details/167
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术