如何使用Entity Framework将SQL数据库连接到MVC4项目 [英] How do I connect a SQL Database to an MVC4 project using Entity Framework
本文介绍了如何使用Entity Framework将SQL数据库连接到MVC4项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Entity Framework将SQL数据库连接到MVC4项目。
我有一个数据库:Astronomy.mdf,它位于mdb项目中。
连接字符串位于:
I am trying to connect a SQL Database to an MVC4 project using Entity Framework.
I have a database: Astronomy.mdf which is located in the mdb project.
The connection string was found at:
https://connectionstrings.com/sql-server/
在web.config中:
In web.config:
<connectionStrings>
<add name="testContext" connectionString="Server=.\SQLExpress;AttachDbFilename=C:\folder\mdb\mdb\App_Data\Astronomy.mdf;Database=Astronomy;Trusted_Connection=Yes;" />
</connectionStrings>
推荐答案
请使用以下链接
http://www.asp.net/mvc/tutorials/ ef-using-mvc / creation-an-entity-framework-data-model-for-an-asp-net-mvc-application [ ^ ]
http://www.asp.net/mvc/tutorials/mvc-5/introduction/creating-a-connection-string [ ^ ]
这两个链接都非常好,可以解决您的问题。
Hi,
Please use below links
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application[^]
http://www.asp.net/mvc/tutorials/mvc-5/introduction/creating-a-connection-string[^]
Both links are very good and will solve your problem.
这篇关于如何使用Entity Framework将SQL数据库连接到MVC4项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文