• Entity Framework Core 3.1 学习笔记1 创建数据库


    using Demo.Domain;
    using Microsoft.EntityFrameworkCore;
    
    namespace Demo.Data
    {
        class DemoContext:DbContext
        {
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                optionsBuilder.UseSqlServer(connectionString: @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Demo;");
                //base.OnConfiguring(optionsBuilder);
            }
            public DbSet<League> Leagues { get; set; }
    
            public DbSet<Club> Clubs { get; set; }
    
            public DbSet<Player> Players { get; set; }
        }
    }

    准备类库:

    using System;
    using System.Collections.Generic;
    
    namespace Demo.Domain
    {
        public class Club
        {
            public Club() {
                Players = new List<Player>();
            }
    
            public int Id { get; set; }
    
            public string Name { get; set; }
    
    
            public string City { get; set; }
    
    
            public DateTime DateOffEstablishment { get; set; }
    
            public string History { get; set; }
    
            public League League { get; set; }
    
            public List<Player> Players { get; set; }
        }
    }
    namespace Demo.Domain
    {
        public class League
        {
            public int Id { get; set; }
    
            public string Name { get; set; }
    
            public string Country { get; set; }
        }
    }
    using System;
    
    namespace Demo.Domain
    {
        public class Player
        {
            public int Id { get; set; }
    
            public string Name { get; set; }
    
            public DateTime DateOfBirth { get;set; }
        }
    }

     

    nuget包:

    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />

    命令工具
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4">

    常用命令:

     get-help EntityFrameworkCore

    clear

    Add-Migration xx
    Drop-Database
    Get-DbContext
    Remove-Migration
    Scaffold-DbContext
    Script-DbContext
    Script-Migration
    Update-Database  -verbose

      

  • 相关阅读:
    SQL LOADER使用
    固定资产新增接口
    固定资产的调整分配接口
    固定资产的完全报废接口
    固定资产更新接口
    详解EBS接口开发之库存事务处理采购接收和退货
    物料分类新增&更新
    物料REVISION控制
    供应商导入的API补充(详解EBS接口开发之供应商导入)
    PostgreSQL经常使用函数
  • 原文地址:https://www.cnblogs.com/tofight/p/14644816.html
Copyright © 2020-2023  润新知