When developing DAL in Entity Framework in a web scenario, somehow I got this error at runtime. Digging into the message, I realized that there are configuration regarding EF metadata we should pay extra attentions on it.
In my case, I want to place all customized biz-logic handlers in %WebSite%\bin\BizLogic folder, and left system related files in <%WebSite%>\bin folder. In this case, we need to specify correct EF metadata path in our web.config file instead of using the defaults.
Say we have a DAL project called FormDesignEntities.
- Open the project in VS2010, open edmx file, and open the Properties window.
- Change the [Metadata Artifact Processing] property to [Copy to Output Directory]
- Compile the project, you will find three files in the output folder; In my case, they are FormDesignEntities.csdl, FormDesignEntities.msl,FormDesignEntities.ssdl. These files contain database schemas and conceptual models.
- Open consuming project, in my case, the Web project; right click on project root, then [Add Existing Item…]
- Select those files and add them into the consuming project as a link
- Compile and deploy the consuming project
- Now open your web.config file, looking for connection strings, your connection string should look like this
<add name="FormDesingEntity"connectionString="metadata=~/bin/FormDesignEntities.csdl|~/bin/FormDesignEntities.ssdl|~/bin/FormDesignEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=tw-bpmdb,3433;initial catalog=BPM_Platform_POC;persist security info=True;user id=sa;password=2wsx#EDC;multipleactiveresultsets=True;App=EntityFramework""providerName="System.Data.EntityClient" />
- See there’re metadata file location settings in this setting, since we are in a web scenario, and I want to put these meta files in bin folder, we can use “~” to reference to web site folder and ~/bin to point to bin folder. Simply modify these path to fit requirements
沒有留言:
張貼留言