简体   繁体   English

如何将我的模型类与MVC 3中的现有数据库绑定?

[英]How do I tie my Model classes with an existing database in MVC 3?

I've written my classes in the Models folder and I already have a database with data in SQL Express. 我已经在Models文件夹中编写了类,并且已经有一个包含SQL Express中数据的数据库。 What I want to do is just tie the two together. 我想做的就是将两者捆绑在一起。 How do I do this? 我该怎么做呢? All I have seen is Code First (class creates database/tables) but that's not what I want. 我所看到的只是Code First(类创建数据库/表),但这不是我想要的。

As Andrew Barber pointed out in his comment, EF with Code First is the way to go, provided the classes in your modell are structurally close if not identical to the tables in your database. 正如安德鲁·巴伯(Andrew Barber)在他的评论中指出的那样,带代码优先的EF是必经之路,只要模型中的类在结构上紧密(如果与数据库中的表不相同)。 Even if the structure is not that compatible current versions of EF can help you a lot with the use of things like views and stored procedures. 即使结构不是那样,兼容的EF当前版本也可以通过使用视图和存储过程之类的东西为您提供很多帮助。

Scott Guthrie has an excellent blog post that should get you started. Scott Guthrie的博客文章很棒,应该可以帮助您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM