Entity Framework 学习第二天
2014-06-15 22:40
169 查看
今天记录的内容不多,只是简单用一下Model first,新建项目,然后添加新建项,选择数据中的ado.net实体数据模型
这次我们选择空模型,然后右键,新增,实体
在这项demo中我打算建两个数据实体,一个studentInfo,classInfo。
得到类似uml图
我们可以在每个图上新增属性,各新增了name属性,在studentInfo上新增cId,空白处右键,新增关联,
右键根据模型生成数据库
实现在数据库建好库,然后选择数据库,就会生成sql语句了。下面是我生成的sql语句
将代码复制到数据库中执行以下就可以了,这就是Model first。code first与Model first并不是一样的。code first 需要我们自己写类,用的不是很多。
这次我们选择空模型,然后右键,新增,实体
在这项demo中我打算建两个数据实体,一个studentInfo,classInfo。
得到类似uml图
我们可以在每个图上新增属性,各新增了name属性,在studentInfo上新增cId,空白处右键,新增关联,
右键根据模型生成数据库
实现在数据库建好库,然后选择数据库,就会生成sql语句了。下面是我生成的sql语句
-- -------------------------------------------------- -- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure -- -------------------------------------------------- -- Date Created: 06/15/2014 22:37:13 -- Generated from EDMX file: C:\Users\admin\documents\visual studio 2012\Projects\EFConsole\ConsoleApplication1\Model1.edmx -- -------------------------------------------------- SET QUOTED_IDENTIFIER OFF; GO USE [EFtest]; GO IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]'); GO -- -------------------------------------------------- -- Dropping existing FOREIGN KEY constraints -- -------------------------------------------------- -- -------------------------------------------------- -- Dropping existing tables -- -------------------------------------------------- -- -------------------------------------------------- -- Creating all tables -- -------------------------------------------------- -- Creating table 'Student' CREATE TABLE [dbo].[Student] ( [id] int IDENTITY(1,1) NOT NULL, [name] nvarchar(max) NOT NULL, [cId] nvarchar(max) NOT NULL, [ClassInfo_id] int NOT NULL ); GO -- Creating table 'ClassInfo' CREATE TABLE [dbo].[ClassInfo] ( [id] int IDENTITY(1,1) NOT NULL, [name] nvarchar(max) NOT NULL ); GO -- -------------------------------------------------- -- Creating all PRIMARY KEY constraints -- -------------------------------------------------- -- Creating primary key on [id] in table 'Student' ALTER TABLE [dbo].[Student] ADD CONSTRAINT [PK_Student] PRIMARY KEY CLUSTERED ([id] ASC); GO -- Creating primary key on [id] in table 'ClassInfo' ALTER TABLE [dbo].[ClassInfo] ADD CONSTRAINT [PK_ClassInfo] PRIMARY KEY CLUSTERED ([id] ASC); GO -- -------------------------------------------------- -- Creating all FOREIGN KEY constraints -- -------------------------------------------------- -- Creating foreign key on [ClassInfo_id] in table 'Student' ALTER TABLE [dbo].[Student] ADD CONSTRAINT [FK_StudentInfoClassInfo] FOREIGN KEY ([ClassInfo_id]) REFERENCES [dbo].[ClassInfo] ([id]) ON DELETE NO ACTION ON UPDATE NO ACTION; -- Creating non-clustered index for FOREIGN KEY 'FK_StudentInfoClassInfo' CREATE INDEX [IX_FK_StudentInfoClassInfo] ON [dbo].[Student] ([ClassInfo_id]); GO -- -------------------------------------------------- -- Script has ended -- --------------------------------------------------
将代码复制到数据库中执行以下就可以了,这就是Model first。code first与Model first并不是一样的。code first 需要我们自己写类,用的不是很多。
相关文章推荐
- Python学习第二天
- hibernate学习 第二天
- 第二天ASP.NET学习总结
- 今天是正式学习C语言的第二天,收获不小!
- 跟“无为”学习Ajax技术第二天
- JAVA设计模式学习第二天 设计模式之Factory——买货篇
- 学习YUI.Ext 第二天
- 学习LINUX第二天:在虚拟机中进入XWINDOWS
- 正则表达式学习第二天——入门
- 学习CRYPTO第二天
- 马牛的C#学习(第二天)-熟悉VS2005环境
- 学习ASP.NET第二天
- .NET 学习 第二天
- 全面学习ASP第二天
- 学习3dmax的第二天
- 第二天SL275的学习
- C# 学习笔记 -- 第二天 使用注释提高代码可读性
- 学习YUI.Ext 第二天
- 报名参加VBA学习的第二天
- 跟“无为”学习Ajax技术第二天