Question

How can i change this.ObjectContext.Connection in Domain Service Constructor?

I use multi Datamodel and Multi Domain Service.

    ...    
    <add name="PermissionEntities" connectionString="metadata=res://*/Entities.General.Permission.csdl|res://*/Entities.General.Permission.ssdl|res://*/Entities.General.Permission.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=10.10.10.10;initial catalog=Development;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="ProfileEntities" connectionString="metadata=res://*/Entities.General.Profile.csdl|res://*/Entities.General.Profile.ssdl|res://*/Entities.General.Profile.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=10.10.10.10;initial catalog=Development;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    ...

I want to change '.csdl' , '.ssdl' , '.msl' at runtime in Domain Service constructor.

Was it helpful?

Solution

It's solved by override CreateObjectContext in Domain Service Class.

protected override Connection CreateObjectContext()
{  
     // Start out by creating the SQL Server connection string
     SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();

     // Set the properties for the data source. The IP address network address
     sqlBuilder.DataSource = @"10.10.10.10";

     // The name of the database on the server
     sqlBuilder.InitialCatalog = "Development";
     sqlBuilder.IntegratedSecurity = true;
     sqlBuilder.MultipleActiveResultSets = true;
     sqlBuilder.ApplicationName = "EntityFramework";

     // Now create the Entity Framework connection string
     EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();

     //Set the provider name.
     entityBuilder.Provider = "System.Data.SqlClient";

     // Set the provider-specific connection string.
     entityBuilder.ProviderConnectionString = sqlBuilder.ToString();

     // Set the Metadata location. 
     entityBuilder.Metadata = @"res://*/Entities.Permission.csdl|res://*/Entities.Permission.ssdl|res://*/Entities.Permission.msl";

     // Create and entity connection
     EntityConnection conn = new EntityConnection(entityBuilder.ToString());

     return new Connection(conn);    
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top