开发者

importing a pre-existing edmx file is a new vs 2010 solution

Hi I started from scr开发者_StackOverflow中文版ath a new vs 2010 solution. How can I add a preexisting edmx file generated with the vs tool avoiding mess :)? (The cleanest way)

Thanks a lot!!


I am quite sure that adding the edmx file as an existing Item will work quite well. You will have to add the adequate connectionString in your config file however.

<add name="<EntityContainerName>" connectionString="metadata=res://*/<pathToEDMX>.csdl|res://*/<pathToEDMX>.ssdl|res://*/<pathToEDMX>.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=localhost;Initial Catalog=MyDatabase;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

where pathToEDMX is the path to your edmx file in the project (for exemple Models.Model if you included the Model.edmx file in the Models directory of your project)

You will want to change the database connection string in this mmodel connection string too.

In order for this connecion string to work, the model option "Metadata Artifact Processing" must be set to "Embed in Output Assembly"


I agree with the Eilistraee, But I have another openion which is very much procedural. you can add this existing edmx file to your project. then you can open the edmx file and create database from this model(this can be done by right clicking on the entity diagram. ), when you select the proper database, it will automatically create the connection string in your app.config. Good luck.


If you want to do this, the way I found to do this is:

  1. Open the solution that the contains the project you wish to import into.
  2. Add the project that contains the edmx you want to import.
  3. Copy and paste the edmx file from one project to the other.
  4. Remove the second project and proceed.
  5. This might be necessary: Open the edmx, adjust namespace, etc and save it.

VS 2013 and EF 6.1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜