How to use ADO.net Entity Framework with an existing SqlConnection?

That forum post has the answer: MetadataWorkspace workspace = new MetadataWorkspace( new string { "res://*/" }, new Assembly { Assembly. GetExecutingAssembly() }); using (SqlConnection sqlConnection = new SqlConnection(connectionString)) using (EntityConnection entityConnection = new EntityConnection(workspace, sqlConnection)) using (NorthwindEntities context = new NorthwindEntities(entityConnection)) { foreach (var product in context. Products) { Console.

WriteLine(product. ProductName); } } res://*/" is the part of your EF connection string that describes the location of your xml mapping files - in this case embedded resources in the current assembly.

That forum post has the answer: MetadataWorkspace workspace = new MetadataWorkspace( new string { "res://*/" }, new Assembly { Assembly. GetExecutingAssembly() }); using (SqlConnection sqlConnection = new SqlConnection(connectionString)) using (EntityConnection entityConnection = new EntityConnection(workspace, sqlConnection)) using (NorthwindEntities context = new NorthwindEntities(entityConnection)) { foreach (var product in context. Products) { Console.

WriteLine(product. ProductName); } } "res://*/" is the part of your EF connection string that describes the location of your xml mapping files - in this case embedded resources in the current assembly.

Thanks, Now I get this error: MetadataWorkspace must have EdmItemCollection pre-registered. The project is an Asp. Net Web page with an .

Edmx file. I think its not getting the data from the . Edmx file.

– EZ. Feb 6 '09 at 18:49 1 I had the same problem but you change Assembly. GetExecutingAssembly() to Assembly.

GetAssembly(typeof(NorthwindEntities)) it got it working nicely. – Hath Dec 10 '09 at 12:48.

You can do this by using the constructor of your generated ObjectContext that accepts an EntityConnection. When you create the EntityConnection you pass in your SqlConnection.

I have been going around and around with the System.Data.EntityClient. EntityConnection. It’s right there at my finger tips but I cannot seem to get the MetadataWorkspace parameter to work.

– EZ. Feb 6 '09 at 5:57.

Andrew Peters, Thank you for your answer. I have been going around and around with the System.Data.EntityClient. EntityConnection.

It’s right there at my finger tips but I cannot seem to get the MetadataWorkspace parameter to work. This is the closest example I have found (the post marked Answer): social.msdn.microsoft.com/Forums/en-US/a... Thanks for any help.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions