我有现有的数据库。 enityframework的哪种方法最适合在MVC中开发Web应用程序 [英] i have existing database. which approach of enityframework is best to develop web application in MVC

查看:85
本文介绍了我有现有的数据库。 enityframework的哪种方法最适合在MVC中开发Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我在sql server中有数据库,表,列和记录。我想将我的asp.net Web应用程序项目迁移到MVC中。



因此,我需要在MVC中使用实体框架。但EF有三种方法(架构优先,模型优先,代码优先)。对于我的情况我应该使用哪种方法,最好用三种方法?



谢谢

解决方案

既然你已经有你的数据库,采用架构第一种方法。但是你最好在DBA之前检查数据库设计并在迁移之前纠正/改进。 查看此帖子,比较所有这些方法,它可以帮助您做出决定。


对于您的查询,Database First是最佳方法,正如您所说,您已预先存在数据库。 MVC中的Entity框架非常智能,可以使用T4模板为表实体生成类。

您只需添加连接字符串,然后从数据库更新模型。这将在 .edmx 文件中为表提供关系图,在 .tt 文件中创建实体,并且从服务器与数据库进行交互也需要上下文。

C#Corner [ ^ ]

查看上面的文章。很好地解释了。

ASP.Net社区 [ ^ ]

Hello,

I have database, table ,columns and records in sql server. I want to migrate my asp.net web application project into MVC.

So, for that i need to use entity framework in MVC. But EF has three approach(schema first,model first and code first). for my case which approach i should use and best among three approaches?

Thanks

解决方案

Since you have your database already, go with schema first approach. but you better check the database design by DBA and correct/improve before migration. check this post which comparing all these approaches and it may help you to take the decision.


For your query, Database First is the Best approach, as you say you have pre-existing database. The Entity framework in MVC is smart enough to generate the classes for your table entities using T4 template.
You just need to add the connection strings and then update the model from the Database. This will give the Tables with relationships diagram in an .edmx file, creating the entities in a .tt file and the Context also which will be required for interacting with the databse from the server.
C#Corner[^]
Check the above article. Nicely explained.
ASP.Net community[^]


这篇关于我有现有的数据库。 enityframework的哪种方法最适合在MVC中开发Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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