I want to use the existing SqlConnection object that I use throughout the site for the Entity Framework connection.
I do not want to have to use a second database connection for the one page that is going to use the ADO.net Entity Framework and I don’t want to change the entire site to use the new Entity Framework connection string.
Thanks for any help you can provide.
Entity Framework is the development of data-oriented applications using ADO.NET. Entity Framework solves problems in entity models, relationships, and business logic. Also, it works with data engines. This means Entity Framework is an Object-Relational Mapping (ORM) framework.
Attachments: Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.
Create the ADO.NET Entity Data ModelRight-click on your project in the Solution Explorer window and select the menu option Add -> New Item. In the Add New Item dialog, select the Data category. Select the ADO.NET Entity Data Model template, give the Entity Data Model the name Northwind. edmx, and click the Add button.
To connect to Microsoft SQL Server, use the SqlConnection object of the . NET Framework Data Provider for SQL Server. To connect to an OLE DB data source, use the OleDbConnection object of the .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With