实体框架5-从实体迁移和创建表 [英] Entity Framework 5 - Migrations and creating table from entity

查看:68
本文介绍了实体框架5-从实体迁移和创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Entity Framework 5 RC,并且我有一些代码需要在数据库上使用特定的表。该实体已经使用Code-First创建。

I am using Entity Framework 5 RC and i have some code that require a specific table on the database. The entity is already created using Code-First.

a)如果尚未在数据库中创建表,是否可以告诉EF创建表?如果是的话..怎么样?
b)另外..如果表已经存在,它可以处理实体更改,例如为实体添加属性..它将反映在数据库上吗? (我们仍在这里使用代码优先方法)

a) Is there a way to tell EF to create the table if its not already created in the database ? If yes.. how ? b) Also.. if the table already exist, can it handle entity changes such adding properties to the entity.. will it get reflected on the database ? (We still use the code-first approach here)

谢谢!

推荐答案

使用代码优先迁移(自动基于代码)。如果要将表添加到现有数据库,请创建初始迁移,然后添加新实体。所有链接均适用于EF 4.3,但用法与EF 5完全相同。

Use code first migrations (either automatic or code based). If you are adding table to existing database create initial migration first and than add your new entity. All links are for EF 4.3 but the usage is exactly the same in EF 5.

这篇关于实体框架5-从实体迁移和创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆