Changing the Name of the Connection String that Entity Framework Uses

拟墨画扇 提交于 2019-12-21 08:00:48

问题


How do you change the name of the connection string that Entity Framework models are bound to by default?

Let's say I create an Entity Framework data model named "Model1.edmx" by pointing it to a databased named "MyDb" and picking some objects to map using the Visual Studio add new item wizard. The EF model is in a class library project, so when the wizard completed, it automatically added a connection string named "MyDbEntities" to the App.Config file for the project. My model references this connection string by default.

I know I can pass in a connection string to a constructor for my model's object context, but how can I change the name of the default connection string?

I'm using VS 2010 Beta 2.


回答1:


The default connection string name is simply the same as the Entity Container Name of your model.

So if you open up your model, click on a blank area, then go to the Properties window, you can look for the Entity Container Name and change it.

Note that the Entity Container Name is also used for other things. E.g., it's the class name of your ObjectContext subtype, and it's used when creating EntityKeys.



来源:https://stackoverflow.com/questions/2280732/changing-the-name-of-the-connection-string-that-entity-framework-uses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!