将新表添加到EF [英] Add new table to EF

查看:108
本文介绍了将新表添加到EF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Entity Framework的MVC4(VS 2012)项目.我已经通过连接到SQL Server 2008创建了一个模型.效果很好.

I have a project in MVC4 (VS 2012) with Entity Framework. I have created a model by connecting to SQL Server 2008. Works great.

现在,我想向模型添加一个或多个表.

Now I want to add one or more tables to the model.

这是我所做的:

  1. 打开.edmx文件.
  2. 右键单击并从数据库中选择更新模型.
  3. 在添加"选项卡下,它显示表,视图和存储过程.

但是没有一个是可选择的.我在这里想念什么吗?

But none of them is selectable. Am I missing something here?

推荐答案

Murali,据我所知,问题在于自创建模型以来,您没有对数据库进行任何更改.如果此说法正确,请查看以下内容:

Murali, if I understood well, the problem is that you didn't make changes to the database since you've created the model. If this statement is correct, take a look at this:

从模型开始添加表是一种模型优先的方法.从代码开始是一种代码优先的方法.但是,您正在尝试从现有数据库更新模型.这是一种数据库优先的方法.对于数据库优先方法,您提到的步骤是正确的.

Add tables starting from the model is a Model-first approach. Starting from code is a Code-first approach. However, you are trying to update the model from a existing database. That is a Database-first approach. For a database-first approach, the steps you mentioned are right.

但是,在这种方法中,您不应该尝试从模型开始开发新表.相反,您应该打开SQL Server Management Studio(或数据库项目)并在其中编码新的架构.然后,在对架构中的更新进行编码之后,您可以返回模型并按照您描述的步骤进行操作.

However, in this approach you shouldn't be trying to develop new tabes starting from the model. Instead, you should open your sql server management studio (or database project) and code the new schema there. Then, after coding the updates in the schema, you go back to your model and follow the steps that you described.

希望有帮助.

这篇关于将新表添加到EF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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