您正在尋找這樣的事情:
public abstract class Stats
{
// put your fields here
public bool Exists { get; set; }
public int Count { get; set; }
public Frob Foo { get; set; }
public abstract void Fill();
}
public class UniquesProcedureStats : Stats
{
public override void Fill()
{
// make call to call Uniques
this.Exists = false;
this.Count = 1
}
}
public class HitsProcedureStats : Stats
{
public override void Fill()
{
// make call to call HitsProcedure
this.Exists = true;
this.Foo = new Frob();
}
}
或者,也許是這樣的:
public abstract class Stats
{
// put your fields here
public bool Exists { get; set; }
public int Count { get; set; }
public Frob Foo { get; set; }
public abstract void Fill(string procedureName)
{
SqlConnection connection = new SqlConnection("Get your own connection string");
connection.Open();
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = procedureName; // your query may be more complicated than this?
using (var reader = command.ExecuteReader())
{
reader.Read();
this.Count = (int)reader["Count"];
}
}
}
您將需要重新解釋這個 - 我已經看過兩遍兩次都沒有意義。 – JonH
你如何從不同的表格返回相同的結果?至少,返回值將是不同類型的(即,與該特定表關聯的LINQ-to-SQL DBML類型)。 – mellamokb
嗨,很抱歉,我想分享多個結果類型之間的方法,或者將一個結果類型與可應用於我的數據的方法分享。 – Darren