Recently I started working with EF 4.1 in .NET and had sort of positive experience until today when I tried to set up my own project (so far I was working on projects started by somebody else).
The thing just doesn't want to work out of the box. I don't do anything special. Actually, first it worked, then it stopped working out of blue and now after 4 hours of wasting my time I am writing this post.
My solution consists of 3 projects:
WebApp (where my app live) DataAccess BusinessObjectsDataAccess contains EntityModel.edmx and EntityModel.Context.tt file.
BusinessObjects contains EntityModel.tt with all underlying objects. I used ADO.NET DbContext generator to generate objects. Namespace for EntityModel.Context.tt is set to BusinessObjects.WebApp and DataAccess are referencing BusinessObjects project. BusinessObjects doesn't reference anything.
(I believe I did set up this correctly. EntityModle.tt is able to see edmx file and objects get created when I edit file.)
So, at this point projects compile nicely with no errors.
In my next step I am adding EntityDataSource to my default.aspx page and after I choose my connection in datasource configuration (one from web.config) I get error: The metadata specified in this connection string could not be loaded. Consider rebuilding web pro开发者_开发知识库ject... Unable to load specified metadata resource.
I had this problem before when I would misspell something in my connection string, change model name, or similar, but now I didn't do anything. I recreated edmx file and its POCOs several times making sure I copy connection string from app.config. It simply doesn't work.
Any help is appreciated. Thanks.
You will have to change the connection string in your web.config as such:
connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider...etc...
Basically: metadata=res://*/; will try to find the embedded metadata files (csdl, msl, ssdl) in all the referenced assemblies in the project and you'll have a better luck locating the embedded resources that are generated as artifacts of the edmx file.
Hope this helps.
精彩评论