• asp.net Mvc 增删改查


    1.创建项目

     

    已经创建好项目了

    2.创建数据库

    使用这个数据库或者自己创建一个数据库,一个表就好,简单

    复制代码
    USE [LearnAdminlte]
    GO
    /****** Object:  Table [dbo].[__EFMigrationsHistory]    Script Date: 2019/7/30 9:28:39 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[__EFMigrationsHistory](
        [MigrationId] [nvarchar](150) NOT NULL,
        [ProductVersion] [nvarchar](32) NOT NULL,
     CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY CLUSTERED 
    (
        [MigrationId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    /****** Object:  Table [dbo].[Admin]    Script Date: 2019/7/30 9:28:39 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Admin](
        [Id] [nvarchar](36) NOT NULL,
        [Name] [nvarchar](max) NULL,
        [Account] [nvarchar](max) NULL,
        [Password] [nvarchar](max) NULL,
        [Email] [nvarchar](max) NULL,
        [CreateTime] [datetime2](7) NOT NULL,
     CONSTRAINT [PK_Admin] PRIMARY KEY CLUSTERED 
    (
        [Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    
    GO
    /****** Object:  Table [dbo].[Bolg]    Script Date: 2019/7/30 9:28:39 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Bolg](
        [Id] [nvarchar](36) NOT NULL,
        [Title] [nvarchar](max) NULL,
        [ReadCount] [int] NOT NULL,
        [Content] [nvarchar](max) NULL,
        [Bolg_category_Id] [nvarchar](max) NULL,
        [CreateTime] [datetime2](7) NOT NULL,
        [Like] [int] NOT NULL,
        [Fack] [int] NOT NULL,
        [AdminId] [nvarchar](max) NULL,
     CONSTRAINT [PK_Bolg] PRIMARY KEY CLUSTERED 
    (
        [Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    
    GO
    /****** Object:  Table [dbo].[Categorys]    Script Date: 2019/7/30 9:28:39 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Categorys](
        [Id] [nvarchar](36) NOT NULL,
        [CategotyName] [nvarchar](max) NULL,
        [AdminId] [nvarchar](max) NULL,
     CONSTRAINT [PK_Categorys] PRIMARY KEY CLUSTERED 
    (
        [Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    
    GO
    /****** Object:  Table [dbo].[Person]    Script Date: 2019/7/30 9:28:39 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Person](
        [Id] [nvarchar](36) NOT NULL,
        [Name] [nvarchar](max) NULL,
        [Age] [int] NOT NULL,
        [Occupation] [nvarchar](max) NULL,
        [Birthday] [datetime2](7) NOT NULL,
     CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED 
    (
        [Id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    
    GO
    复制代码

     3.在MVC程序中创建ADO.NET 实体数据模型

    来自数据库的Code first

    创建连接字符串

    创建好了就可以看到这些东西 Dbcontext   Web.config下的连接字符串

     

    创建一个具有读写操作的控制器

     

     
  • 相关阅读:
    如何替换文件中的部分内容?
    将文件中的行倒序输出,并写入文件
    如何统计文件中除去空行的数据的行数?
    统计文件行数,统计特殊行(例如,统计含有数字的行数)
    Array,String,Set,Map
    python 操作 word 图片 消失
    es6
    Promise
    英文
    前端框架vue.js系列(9):Vue.extend、Vue.component与new Vue
  • 原文地址:https://www.cnblogs.com/shijiehaiyang/p/12905395.html
Copyright © 2020-2023  润新知