标签:ddb open ini services ram asp ons closed ISE
之前用过.Net Framework 的EF功能,现在记录下.Net Core环境下的学习情况,以方便之后部署环境使用。
首先创建一个.Net Core Web端程序,我用的是vs可视化界面创建的,控制台端命令模式创建没有研究
install-package Microsoft.EntityFrameworkCore.SqlServer
添加EF引用包
创建一个Model文件 OrderContext
public class OrderContext : DbContext { public OrderContext(DbContextOptions<OrderContext> options) : base(options) { } public DbSet<Order> Blogs { get; set; } public DbSet<Post> Posts { get; set; } } public class Order { public int OrderId { get; set; } public string OrderName { get; set; } public ICollection<Post> Posts { get; set; } } public class Post { public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public int OrderId { get; set; } public Order Order { get; set; } }
通过依赖关系注入注册服务
public void ConfigureServices(IServiceCollection services) { var connection = @"Server=.;Database=Blogging;Trusted_Connection=True;ConnectRetryCount=0"; services.AddDbContext<BloggingContext>(options => options.UseSqlServer(connection)); }
Add-Migration InitialCreate Update-Database
标签:ddb open ini services ram asp ons closed ISE
原文地址:https://www.cnblogs.com/Gavin-Leo/p/12493646.html