企业库映射
Enterprise Library Mappings
有没有一种方法可以使用 Enterprise Library 将数据库字段映射到 OOP 复杂类型字段。我正在调用存储过程来检索我想存储到自定义 class.
中的所有数据
这里我从 sp:
中获取数据
IEnumerable<WorkHistoryGrid> data = new List<WorkHistoryGrid>();
return db.ExecuteSprocAccessor<WorkHistoryGrid>("PensionPDF_RetrieveParticipantWorkHistoryForFund", pensionId, fund);
这是我的 class
public class WorkHistoryGrid : BindableBase
{
private string _rateType;
private string _fundType;
private string _employer;
private string _employerName;
private string _local;
private string _dateBalanced;
private string _plan;
private string _fund;
private WorkHistoryGridMergeData _mergeData;
#region Properties
public WorkHistoryGridMergeData MergeData
{
get { return _mergeData; }
set { SetProperty(ref _mergeData, value); }
}
public string RateType
{
get { return _rateType; }
set { SetProperty(ref _rateType, value); }
}
public string FundType
{
get { return _fundType; }
set { SetProperty(ref _fundType, value); }
}
public string Employer
{
get { return _employer; }
set { SetProperty(ref _employer, value); }
}
public string EmployerName
{
get { return _employerName; }
set { SetProperty(ref _employerName, value); }
}
public string Local
{
get { return _local; }
set { SetProperty(ref _local, value); }
}
public string DateBalanced
{
get { return _dateBalanced; }
set { SetProperty(ref _dateBalanced, value); }
}
public string Plan
{
get { return _plan; }
set { SetProperty(ref _plan, value); }
}
public string Fund
{
get { return _fund; }
set { SetProperty(ref _fund, value); }
}
}
}
}
如果我创建一个包含所有数据库字段的 class 效果很好,但我想通过将数据库字段映射到自定义复杂类型属性来更好地控制它。
这是我的答案,以防有人寻找类似的解决方案:
var workHistoryGridSetMapper = new WorkHistoryGridSetMapper();
db.ExecuteSprocAccessor<WorkHistoryGrid>("PensionPDF_RetrieveParticipantWorkHistory", workHistoryGridSetMapper, pensionId);
IResultSetMapper
public class WorkHistoryGridSetMapper : IResultSetMapper<WorkHistoryGrid>
{
public IEnumerable<WorkHistoryGrid> MapSet(IDataReader reader)
{
List<WorkHistoryGrid> workHistoryLst = new List<WorkHistoryGrid>();
using (reader) // Dispose the reader when we're done
{
while (reader.Read())
{
WorkHistoryGrid workHist = new WorkHistoryGrid();
workHist.Amount = reader.GetValue(reader.GetOrdinal("Amount")).ToString();
workHist.DateBalanced = reader.GetValue(reader.GetOrdinal("DateBalanced")).ToString();
workHist.Employer = reader.GetValue(reader.GetOrdinal("Employer")).ToString();
workHist.EmployerName = reader.GetValue(reader.GetOrdinal("EmployerName")).ToString();
workHist.Fund = reader.GetValue(reader.GetOrdinal("Fund")).ToString();
workHist.FundType = reader.GetValue(reader.GetOrdinal("FundType")).ToString();
workHist.Hours = reader.GetValue(reader.GetOrdinal("Hours")).ToString();
workHist.Local = reader.GetValue(reader.GetOrdinal("Local")).ToString();
workHist.Period = reader.GetValue(reader.GetOrdinal("Period")).ToString();
workHist.Plan = reader.GetValue(reader.GetOrdinal("Plan")).ToString();
workHist.RateAmount = reader.GetValue(reader.GetOrdinal("RateAmount")).ToString();
workHist.RateType = reader.GetValue(reader.GetOrdinal("RateType")).ToString();
workHist.Status = reader.GetValue(reader.GetOrdinal("Status")).ToString();
workHist.WorkMonth = reader.GetValue(reader.GetOrdinal("WorkMonth")).ToString();
workHist.MergeData = new WorkHistoryGridMergeData
{
MergeDateMerged = reader.GetValue(reader.GetOrdinal("MergeDateMerged")).ToString(),
MergeLastUpdated = reader.GetValue(reader.GetOrdinal("MergeLastUpdated")).ToString(),
MergeLastUpdatedUserId = reader.GetValue(reader.GetOrdinal("MergeLastUpdatedUserId")).ToString(),
MergeLastUpdatedUserType = reader.GetValue(reader.GetOrdinal("MergeLastUpdatedUserType")).ToString(),
MergeNewSsn = reader.GetValue(reader.GetOrdinal("MergeNewSsn")).ToString(),
MergeNotes = reader.GetValue(reader.GetOrdinal("MergeNotes")).ToString(),
MergeOldSsn = reader.GetValue(reader.GetOrdinal("MergeOldSsn")).ToString(),
MergeTrustId = reader.GetValue(reader.GetOrdinal("MergeTrustId")).ToString(),
MergeUserName = reader.GetValue(reader.GetOrdinal("MergeUserName")).ToString()
};
workHistoryLst.Add(workHist);
};
}
return workHistoryLst;
}
}
有没有一种方法可以使用 Enterprise Library 将数据库字段映射到 OOP 复杂类型字段。我正在调用存储过程来检索我想存储到自定义 class.
中的所有数据这里我从 sp:
中获取数据 IEnumerable<WorkHistoryGrid> data = new List<WorkHistoryGrid>();
return db.ExecuteSprocAccessor<WorkHistoryGrid>("PensionPDF_RetrieveParticipantWorkHistoryForFund", pensionId, fund);
这是我的 class
public class WorkHistoryGrid : BindableBase
{
private string _rateType;
private string _fundType;
private string _employer;
private string _employerName;
private string _local;
private string _dateBalanced;
private string _plan;
private string _fund;
private WorkHistoryGridMergeData _mergeData;
#region Properties
public WorkHistoryGridMergeData MergeData
{
get { return _mergeData; }
set { SetProperty(ref _mergeData, value); }
}
public string RateType
{
get { return _rateType; }
set { SetProperty(ref _rateType, value); }
}
public string FundType
{
get { return _fundType; }
set { SetProperty(ref _fundType, value); }
}
public string Employer
{
get { return _employer; }
set { SetProperty(ref _employer, value); }
}
public string EmployerName
{
get { return _employerName; }
set { SetProperty(ref _employerName, value); }
}
public string Local
{
get { return _local; }
set { SetProperty(ref _local, value); }
}
public string DateBalanced
{
get { return _dateBalanced; }
set { SetProperty(ref _dateBalanced, value); }
}
public string Plan
{
get { return _plan; }
set { SetProperty(ref _plan, value); }
}
public string Fund
{
get { return _fund; }
set { SetProperty(ref _fund, value); }
}
}
}
}
如果我创建一个包含所有数据库字段的 class 效果很好,但我想通过将数据库字段映射到自定义复杂类型属性来更好地控制它。
这是我的答案,以防有人寻找类似的解决方案:
var workHistoryGridSetMapper = new WorkHistoryGridSetMapper();
db.ExecuteSprocAccessor<WorkHistoryGrid>("PensionPDF_RetrieveParticipantWorkHistory", workHistoryGridSetMapper, pensionId);
IResultSetMapper
public class WorkHistoryGridSetMapper : IResultSetMapper<WorkHistoryGrid>
{
public IEnumerable<WorkHistoryGrid> MapSet(IDataReader reader)
{
List<WorkHistoryGrid> workHistoryLst = new List<WorkHistoryGrid>();
using (reader) // Dispose the reader when we're done
{
while (reader.Read())
{
WorkHistoryGrid workHist = new WorkHistoryGrid();
workHist.Amount = reader.GetValue(reader.GetOrdinal("Amount")).ToString();
workHist.DateBalanced = reader.GetValue(reader.GetOrdinal("DateBalanced")).ToString();
workHist.Employer = reader.GetValue(reader.GetOrdinal("Employer")).ToString();
workHist.EmployerName = reader.GetValue(reader.GetOrdinal("EmployerName")).ToString();
workHist.Fund = reader.GetValue(reader.GetOrdinal("Fund")).ToString();
workHist.FundType = reader.GetValue(reader.GetOrdinal("FundType")).ToString();
workHist.Hours = reader.GetValue(reader.GetOrdinal("Hours")).ToString();
workHist.Local = reader.GetValue(reader.GetOrdinal("Local")).ToString();
workHist.Period = reader.GetValue(reader.GetOrdinal("Period")).ToString();
workHist.Plan = reader.GetValue(reader.GetOrdinal("Plan")).ToString();
workHist.RateAmount = reader.GetValue(reader.GetOrdinal("RateAmount")).ToString();
workHist.RateType = reader.GetValue(reader.GetOrdinal("RateType")).ToString();
workHist.Status = reader.GetValue(reader.GetOrdinal("Status")).ToString();
workHist.WorkMonth = reader.GetValue(reader.GetOrdinal("WorkMonth")).ToString();
workHist.MergeData = new WorkHistoryGridMergeData
{
MergeDateMerged = reader.GetValue(reader.GetOrdinal("MergeDateMerged")).ToString(),
MergeLastUpdated = reader.GetValue(reader.GetOrdinal("MergeLastUpdated")).ToString(),
MergeLastUpdatedUserId = reader.GetValue(reader.GetOrdinal("MergeLastUpdatedUserId")).ToString(),
MergeLastUpdatedUserType = reader.GetValue(reader.GetOrdinal("MergeLastUpdatedUserType")).ToString(),
MergeNewSsn = reader.GetValue(reader.GetOrdinal("MergeNewSsn")).ToString(),
MergeNotes = reader.GetValue(reader.GetOrdinal("MergeNotes")).ToString(),
MergeOldSsn = reader.GetValue(reader.GetOrdinal("MergeOldSsn")).ToString(),
MergeTrustId = reader.GetValue(reader.GetOrdinal("MergeTrustId")).ToString(),
MergeUserName = reader.GetValue(reader.GetOrdinal("MergeUserName")).ToString()
};
workHistoryLst.Add(workHist);
};
}
return workHistoryLst;
}
}