Maybe it is duplicate, but I couldn't succeed to find needed answer.
Actually I am trying to build generic wrapper in order to work with Entity/L2Sql via wcf. So on the server side:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class MyDbContext<TTable> : IMyDbContext<TTable> where TTable:class
{
private readonly DataContext _dbContext;
private readonly Table<Device> _table;
public MyDbContext()
{
_dbContext = new WCF_DataContext(connection);
_table = _dbContext.GetTable<TTable>();
}
public void InsertOnSubmit(TTable table)
{
_table.InsertOnSubmit(table);
}
...and the same stuff further...
}
and on the client side I am using like this
var client = new ServiceRef.MyDbContextClient<ServiceRef.PersonTable>();
client.GetData(); client.insertOnSubmit(); ...other stuff...
I understand what WCF created for universal stuff, different languages, and its natural to forbid straight T, but maybe there is a way to aproach this with some attributes or descriptions (like where T:DataContractAttribute, but this is invalid).
Or maybe I started to think wrong way=)
For some viewmodels I need one DbContext per viewmodel, instead of short using (..dbcontext..)
Maybe you can use known type atribute on your contract.
You can find out more information here:
https://msdn.microsoft.com/en-us/library/ms730167(v=vs.110).aspx
Hope it helps.