How to specify that type should be a class inherited from Interface? I tried various variants but no sense.
public class CarDal<TCarMark> where TCarMark:class//also tried ICarMark
{
...
private static readonly DataContext Context = new DataContext(ConnectionString);
private Table<ICarMark> _tblCarMarks = Context.GetTable<TCarMark>();//Error is "Cannot convert source type 'Table<TCarMark> to target type Table<ICarMark>'"
...
}
Your constraint, especially combining the two forms you cite, is fine:
The problem is variance.
A
Table<TCarMark>has no covariant/contravariant relationship with aTable<ICarMark>You must use
Table<TCarMark>throught this class:However! Don’t use a static data-context: