Convert traditional connection string to entity framework connection string using EntityConnectionStringBuilder
I have a traditional ADO.NET connection string like this:
Initial Catalog=QuartermasterMain_Dev;Data Source=localhost;UID=sa;password=Pass@word1
I would like to re-use this connection string in Entity framework, so I need to convert it to entity connection string. Assume I have an entity class called "QuartermasterMainEntities"
We can use EntityConnectionStringBuilder class to construct an entity connection string from traditional connection string.
public partial class QuartermasterMainEntities : DbContext
{
public QuartermasterMainEntities(string strConnectionString)
: base((new EntityConnectionStringBuilder()
{
Metadata = "res://*/QuartermasterEntities.csdl|res://*/QuartermasterEntities.ssdl|res://*/QuartermasterEntities.msl",
Provider = "System.Data.SqlClient",
ProviderConnectionString = strConnectionString
}).ConnectionString)
{
}
}
Initial Catalog=QuartermasterMain_Dev;Data Source=localhost;UID=sa;password=Pass@word1
I would like to re-use this connection string in Entity framework, so I need to convert it to entity connection string. Assume I have an entity class called "QuartermasterMainEntities"
We can use EntityConnectionStringBuilder class to construct an entity connection string from traditional connection string.
public partial class QuartermasterMainEntities : DbContext
{
public QuartermasterMainEntities(string strConnectionString)
: base((new EntityConnectionStringBuilder()
{
Metadata = "res://*/QuartermasterEntities.csdl|res://*/QuartermasterEntities.ssdl|res://*/QuartermasterEntities.msl",
Provider = "System.Data.SqlClient",
ProviderConnectionString = strConnectionString
}).ConnectionString)
{
}
}
Comments