Hi, I want to create a base class for inheritance, but I am having some problems.
I have two classes that do almost identical work, but get the data they work with from different databases and use different internal data structures to manage the data. I want to have a virtual doSomething method in the base and perfectly virtual dataAccess method in the database.
The second problem can be solved using generics, but I can not use generics to solve the first problem, since the DBMl context constructor used is not without parameters.
I'm all wrong about that. I try to be dry, but it seems to work against inheritance.
Sample code below.
class Foo { private _ctx DBML.Database1; // Inherits from System.Data.Linq.DataContext public Foo(string constring) { _ctx = new DBML.Database1(constring); } private DoSomeThing() { FooDataObj = DataAccess(1); } private FooDataObj DataAccess(int ID) { var v = from t in _ctx where t.Id = ID select new FooDataObj(t); return v } } class Bar { private _ctx DBML.Database2; // Inherits from System.Data.Linq.DataContext public Bar(string constring) { _ctx = new DBML.Database2(constring); } private DoSomeThing() { BarDataObj = DataAccess(1); } private BarDataObj DataAccess(int ID) { var v = from t in _ctx where t.Id = ID select new BarDataObj(t); return v } }
Steve source share