我有以下ViewModel:
public class EmployeeCatalogModel
{
public List<StringCatalogModel> EmployeeType { get; set; }
public List<IntCatalogModel> JobTitle { get; set; }
public List<IntCatalogModel> ProfitCenter { get; set; }
public List<IntCatalogModel> Location { get; set; }
public List<IntCatalogModel> HolidayTemplate { get; set; }
}
每个属性可以是StringCatalogModel
或IntCatalogModel
,具体取决于每个表的标识:
Id
为integer
public class IntCatalogModel
{
public int Id { get; set; }
public string Description { get; set; }
}
Id
为string
public class StringCatalogModel
{
public string Id { get; set; }
public string Description { get; set; }
}
好的,所以魔术发生在这里......我将从我的存储过程5中选择(对于每个目录),然后我必须从那里创建EmployeeCatalogModel
。
我现在拥有的是:
using(DbCommand cmd1 = _db.GetStoredProcCommand("sp_employee_catalogs_get")) {
// instantiate my view model class
EmployeeCatalogModel model = new EmployeeCatalogModel();
using(DataSet ds = _db.ExecuteDataSet(cmd1)) {
// loop through each table so I can instantiate the corresponding collection
foreach(DataTable dt in ds.Tables){
switch(dt.TableName){
case "EmployeeType":
model.EmployeeType = new List<StringCatalogModel>();
break;
case "JobTitle":
model.JobTitle = new List<IntCatalogModel>();
break;
}
foreach(DataRow dr in dt.Rows){
// here I have to know what if I need to create an item of IntCatalogModel or StringCatalogModel and added to its corresponding Collection
// ?? any better way to do this????
}
}
}
}
以更好的方式执行此操作的任何方式?