Your question can be rewritten as "How to pass an argument to a generic type constructor with a new() constraint".
From MSDN:
The new constraint specifies that any type argument in a generic class declaration must have a public parameterless constructor.
Since the bare Entity Framework context doesn't contain a parameter-less constructor, iI assume your EMDataContext is your custom context that derives from it:
public class EMDataContext : DbContext
{
// parameterless ctor, since you're using new() in UnitOfWork<TContext>
public EMDataContext() : base(???)
{
}
public EMDataContext(string connectionString) : base(connectionString)
{
}
}
Now, iI would argue that your EMDataContext is incapable of having a parameter-less constructor, hence incapable of the new() constraint as well, especially when you're saying that you do want to pass a connection-string parameter.
Try to change your UnitOfWork to accept an already-initialized context in it's constructor (common pattern):
public class UnitOfWork<TContext>
{
public UnitOfWork(TContext ctx)
{
_ctx = ctx;
}
}
Alternatively (if you still want to "fit the pattern"), try to instantiate the context using Activator:
public class UnitOfWork<TContext>
{
public UnitOfWork(string connectionString)
{
_ctx = (TContext)Activator.CreateInstance(typeof(TContext), new[] { connectionString });
}
}