问题描述
我要创建一个新的MVC应用程序。哪个最好
EF Code First?
模特第一?
Db第一?
我没有固定的数据库设计,我可能会修改现有的表可能会添加新表。
所以哪一个适合我的要求
I'm gonna create a new MVC Application. which is best
EF Code First ?
Model First?
Db First ?
I don't have fixed Database Design ,i may modify existing table may add new table .
so which one is Suitable for my Requirement
推荐答案
我没有固定的数据库设计,我可能会修改现有的表可能会添加新的表。
I don't have fixed Database Design ,i may modify existing table may add new table .
正如你在这里所说,我预计你已经有了一个数据库,将来你可能需要修改。所以我建议选择数据库第一种方法。您只需添加数据库连接字符串,然后从数据库更新模型。您不需要再次创建类,然后生成数据库,因为您已经拥有相同的数据库。每当您添加新表时: -
从数据库更新模型 - >检查添加表(表的名称)
然后,您需要构建一次解决方案,然后为.tt文件运行自定义工具,该文件包含数据库中表的自动生成的类。 />
每当你改变任何表时: -
从数据库更新模型 - >检查刷新选择表名
然后按照上面提到的相同程序。
[]
如果您想重新创建一个新数据库,那么Code first方法可以帮助您。
[]
我希望这对Sir先生有所帮助。
谢谢
As you say here, I anticipate you already have a database and may be you need modification in there in future. So I would suggest to opt for Database first approach. As you just need to add your database connection strings and then Update your model from database. You donot need to create again the classes and then generate the database as you already have the same. Whenever you add a new Table :-
Update model from database-> Check Add table(name of the table)
Then you need to build your solution once and then run custom tool for the .tt file that containes the auto generated classes for your tables in the database.
Whenever you alter any table:-
Update model from database-> Check Refresh select the table name
Then the same procedure mentioned above.
Entity Framework Database First[^]
If you think of recreate a new database, then Code first approach would help you.
Entity Framework Code First[^]
I hope this helps Sir.
thanks
这篇关于EF代码优先或Model First或DB First?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!