あなたが別々のテーブルを維持するための力で、あなただけの 共通のメソッドを書くことができるようにしたい場合は、インターフェイスと以下のような拡張メソッドを使用することができます。
public interface ITableBase{
int Id{ get; set; }
// other properties
void Method1();
int Method2();
string Method3(int some_arguments);
}
public partial class Table1 : ITableBase{
// implement ITableBase and other properties and methods
}
public partial class Table2 : ITableBase{
// implement ITableBase and other properties and methods
}
public partial class Table2 : ITableBase{
// implement ITableBase and other properties and methods
}
static public class ITableBaseExtensions{
static public string GetIdAsString(this ITableBase table){
return table.Id.ToString();
}
static public int UsingMethod2(this ITableBase table){
var i = table.Method2();
return i * 5 + 9 - 14/3 % 7 /* etc... */;
}
static public void AddingNewMethodToTables(this ITableBase table, string some_string,
int some_int, YourType any_other_parameter /* etc... */){
// implement the method you want add to all Table classes
}
//
// You can add any method you want to add to table classes, here, as an Extension method
//
}
と消費者で、あなたはすべてのテーブルのITableBaseExtensions
クラスで定義されたすべてのメソッドを呼び出すことができます。
public class MyConsumer{
public void MyMethod(){
Table1 t1 = new Table1();
Table1 t2 = new Table2();
Table1 t3 = new Table3();
t1.UsingMethod2(); // will be called from ITableBaseExtensions
t1.Method2(); // will be called from ITableBase - must implemented in Table1 class
t2.Method3(some_argument); // will be called from ITableBase - must implemented in Table2 class
t2.GetIdAsString(); // will be called from ITableBaseExtensions
// etc.
}
}
あなたが別の列としてTABLETYPEを持っていないことはできますか? 1つのテーブルを持つことができます。 – Damith
@DSW:パフォーマンス上の理由から分割されています - テーブルごとに何百万もの行がありますので、別々にしておきたいと思います。 – BlueChippy
これはあなたに役立ちますhttp://blogs.msdn.com/b/efdesign/archive/2009/10/12/code-only-further-enhancements.aspx – Damith