Entity Framework 6.x 学习之Database First

一、单表操作

  

  1. 建表

CREATE TABLE [Chapter1].[Customer]
(
[CustomerId] [int] NOT NULL IDENTITY(1, 1),
[Name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Email] [varchar] (1024) COLLATE Chinese_PRC_CI_AS NOT NULL,
[Phone] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [Chapter1].[Customer] ADD CONSTRAINT [PK_Customer_10] PRIMARY KEY CLUSTERED ([CustomerId]) ON [PRIMARY]
GO

2. 创建控制台应用程序 Ex01 ,解决方案名称 EF6xDemo
     3. 建立模型

Entity Framework 6.x 学习之Database First

namespace Ex01
{
using System;
using System.Collections.Generic; public partial class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
}
}

Customer.cs

namespace Ex01
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure; public partial class EFRecipesEntities : DbContext
{
public EFRecipesEntities()
: base("name=EFRecipesEntities")
{
} protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
} public virtual DbSet<Customer> Customers { get; set; }
}
}

EF6RecipesContext.Context.cs

二、主从表操作,and 在数据库里没有建立关系的主从表又该怎么操作?

上一篇:2018-2019-2 20165325《网络对抗技术》Exp0 Kali安装 Week1


下一篇:hdu 5691 Sitting in Line 状压dp