每个表,我都在写很多函数。我需要将这些转换为一个函数。
例如:我有两个 Table Per 功能
private void SelectByRank(int Rank)
{
DBEntities MyDB = new DBEntities();
var Query1 = from P in MyDB.Per
where P.IDRANK == Rank
select P;
}
private void SelectByRankANDBlah(int Rank, string Blah)
{
DBEntities MyDB = new DBEntities();
var Query1 = from P in MyDB.Per
where P.IDRANK == Rank && P.BLAH == Blah
select P;
}
现在,我将转换为一个函数。例如
private void Select(string strKind,int Rank, string Blah)
{
var strWhere ="";
if(strKind == "RANK")
{
strWhere = "where P.IDRANK ==" + Rank;
}
else
{
strWhere = "where P.IDRANK == " + Rank + " && P.BLAH == " + Blah;
}
DBEntities MyDB = new DBEntities();
var Query1 = from P in MyDB.Per
strWhere
select P;
}
好的?