Catel EntitiyFramework Uow and Connectionstring

Topics: Questions
May 14, 2014 at 12:15 PM
Hello

I try to use the UnitOfWork from Catel.

I get an exception on following code

using (var uow = new UnitOfWork<ConfigurationContext>())
{
}

No connection string named 'ConfigurationContext' could be found in the application config file.

My ConnectionString is not defined in the app.config.

I define the ConnectionString in code.
Coordinator
May 14, 2014 at 1:56 PM
I think you can solve this with the ConnectionStringManager.
May 15, 2014 at 5:49 AM
Hm.

I have my own ConnectionString Builder.

Actual Solution (without uow)

I register my class DatabaseInfo
 ServiceLocator.Default.RegisterType(
                s => new DatabaseInfo
                {
                    DatabaseName = Properties.Settings.Default.DatabaseName,
                    ServerName = Properties.Settings.Default.ServerName,
                    ProviderName = Properties.Settings.Default.ProviderName,
                    Metadata = Properties.Settings.Default.Metadata,
                    MultipleActiveResultSets = Properties.Settings.Default.MultipleActiveResultSets,
                    IntegratedSecurity = Properties.Settings.Default.IntegratedSecurity
                });
Then I register my DBContext
ServiceLocator.Default.RegisterType<ConfigurationContext, ConfigurationContext>(RegistrationType.Transient);
ConfigurationContext has following Constructors:
public ConfigurationContext(string nameOrConnectionString)
       :base (nameOrConnectionString)
 {
 }

 public ConfigurationContext(DatabaseInfo info)
       : base(DatabaseClient.GetConnectionString(info))
 {
 }
The ConfigurationContext is now Injected correctly.
public LocationDataManager(ConfigurationContext context) 
{
}
but why not in uow?
May 19, 2014 at 12:31 PM
Hello I cannot find any example with the ConnectionStringManager.

I read also your blog post:

"Entity Framework Unit of Work and repositories"

I don't understand why its default to use the connectionstring in app.config.

In the connectionstring also the hostname of the databaseserver is included. If you have a local database you have to change this name on you destination host.
May 20, 2014 at 9:13 AM
Whats the sense of ConnectionStringManager
public class ConnectionStringManager : IConnectionStringManager
{
    public virtual string GetConnectionString(Type contextType, string database, string label)
    {
        Argument.IsNotNull("contextType", contextType);
        return null;
    }
}
}

??
Coordinator
May 21, 2014 at 9:55 AM