分类:
.Net
需要使用工具的Nuget包管理器添加EF的依赖。
Install-Package Microsoft.EntityFrameworkCore.SqlServer

如果是使用db first,需要根据数据库生成model,就还需要使用命令添加两个依赖
Install-Package Microsoft.EntityFrameworkCore.Tools Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design
相关依赖注入成功之后,就可以再根据一个命令从数据库生成model了
Scaffold-DbContext "Server=.;Database=HouseDB;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
注意:这里的Database=数据库的名称
if版本太低,
看下操作:
链接网页看详细介绍。
https://www.cnblogs.com/tshaoguo/p/10142743.html
然后我们再次使用命令·即可:
Scaffold-DbContext "Server=.;Database=HouseDB;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
生成效果如图所示:
public partial class Blog
{
public Blog()
{
Post = new HashSet<Post>();
}
public int BlogId { get; set; }
public string Url { get; set; }
public ICollection<Post> Post { get; set; }
}
public partial class Post
{
public int PostId { get; set; }
public int BlogId { get; set; }
public string Content { get; set; }
public string Title { get; set; }
public Blog Blog { get; set; }
}评价
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256
50010702506256
欢迎加群交流技术