@担
EntityBase 将是每个实体对象将继承的基类,例如:
public class EntityBase
{
public virtual string SaveSproc { get; }
public virtual void LoadFromReader(SqlReader reader)
{
}
public virtual void Save()
{
List<SqlParameters> paramList = = this.CreateParamsList();
DoSqlStuff(this.SaveSproc, paramList);
}
public virtual List<SqlParamenter> CreateParamsList()
{
return new List<SqlParameter>
}
}
public Company : EntityBase
{
private string _data;
public override string SaveSproc { get { return "SprocThatSaves"; } }
public override List<SqlParameter> CreateParamList()
{
List<SqlParameter> param = new List<SqlParameter>
param.Add(new SqlParameter("Data",_data);
return param;
}
public override void LoadFromReader(SqlReader reader)
{
// PsuedoCode
_data = reader["data"];
}
}
现在,您的数据库层可以让阅读器了解公司数据,并执行以下操作:
Company = new Company();
Company.LoadFromReader(reader);
在其他地方,要保存您的数据:
Company.Save();