Archive for category entity framework

Creating Entity Connection in Linq To Entities ( Entity Framework)

there are key scenarios in which you want to create your connection string at runtime (dynamically), instead of old Connectionstring entity framework uses "EntityConnection" string

now how one will proceed if he wants to create EntityConnection at runtime say read from configuration and then use it or in case of DDR (data dependent routing)  here is the solution that will save you from this trouble.

  • Create Instance of EntityConnectionStringBuilder
  • Assign it the "SQL Connection String"
  • provide the meta data
  • Assign the provider name
  • then all you have to request EntityConnectionStringBuilder to return value from ToString();
  • and you are good to go 🙂
   1: EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
   2: entityBuilder.ProviderConnectionString = connectionstring;
   3: entityBuilder.Metadata = "res://*/";
   4: entityBuilder.Provider = "System.Data.SqlClient";
   5: return entityBuilder.ToString();

kick it on  Shout it