I have a class defined as follows:
public abstract class Repository<TEntity, TDataContext> : DisposableBaseClass where TEntity : class where TDataContext : DataContext, new() {...contains Linq to SQL related functionality
In a particular subclass, I define types as such;
public class ConcreteRepo : Repository<LSTableClass, LSDataContext>
At the next level, I have business objects that store the repository object as a private variable.
That was good,
private ConcreteRepo _repository;
However, I then redid this into the parent class for all business objects - this parent class contains the repository / implements the Dispose pattern to delete the repository, etc.
My problem is that I just cannot get the syntax for declaring a variable.
The closest I came
protected Repository<Object, DataContext> _repository;
but this gives a compilation error:
"Error 1" System.Data.Linq.DataContext "must be a non-abstract type with an open constructor without parameters in order to use it as a parameter" TDataContext "in the generic type or method" .... Repository "..."
I tried other things but ran into other problems.
In the business layer object that inherits this abstract class, I create and use the cast variable _repository;
(Repository<LSTableClass, LSDataContext>)_repository = new ConcreteRepo();
- and I think it will be good if I get this ad directly in the parent.
If I cannot get this to work, I must declare a _repository in each business object with detailed details and implement a delete pattern in each to clear it. Not the end of the world, but I would not want that.