linq将两个表的结果合并到一个选择新状态?
在下面的查询中,我如何更改“选择新”中没有两组字段,我希望信息进入一组没有两个字段的列,以及一个类型字段,以说明是TraineEvent还是cpd事件linq将两个表的结果合并到一个选择新状态?,linq,entity-framework,Linq,Entity Framework,在下面的查询中,我如何更改“选择新”中没有两组字段,我希望信息进入一组没有两个字段的列,以及一个类型字段,以说明是TraineEvent还是cpd事件 List<EmployeeCPDReportRecord> employeeCPDRecords = new List<EmployeeCPDReportRecord>(); string employeeName; var q = from cpd in pamsEntities.Employe
List<EmployeeCPDReportRecord> employeeCPDRecords = new List<EmployeeCPDReportRecord>();
string employeeName;
var q = from cpd in pamsEntities.EmployeeCPDs
from traineeEvent in pamsEntities.TrainingEventTrainees
join Employee e in pamsEntities.Employees on cpd.EmployeeID equals e.emp_no
join TrainingEventPart tEventPart in pamsEntities.TrainingEventParts on traineeEvent.TrainingEventPartId equals tEventPart.RecordId
where (cpd.EmployeeID == id) && (startDate >= cpd.StartDate && endDate <= cpd.EndDate) &&
(traineeEvent.EmployeeId == id)
&& (traineeEvent.TraineeStatus == 1 || traineeEvent.TraineeStatus == 2)
&& (tEventPart.CPDHours > 0 || tEventPart.CPDPoints > 0)
&& (cpd.CPDHours > 0 || cpd.CPDPoints > 0)
|| traineeEvent.StartDate >= startDate
|| traineeEvent.EndDate <= endDate
orderby cpd.StartDate
select new
{
surname = e.surname,
forname1 = e.forename1,
forname2 = e.forename2,
EmployeeID = cpd.EmployeeID,
StartDate = cpd.StartDate,
EndDate = cpd.EndDate,
CPDHours = cpd.CPDHours,
CPDPoints = cpd.CPDPoints,
Description = cpd.Description,
TrainingStartDate = tEventPart.StartDate,
TrainingEndDate = tEventPart.EndDate,
TrainingCPDHours = tEventPart.CPDHours,
TrainingCPDPoints = tEventPart.CPDPoints,
TrainingEventDescription = tEventPart.Description
};
if (q != null)
{
Array.ForEach(q.ToArray(), i =>
{
if (ContextBase.encryptionEnabled)
employeeName = ContextBase.Decrypt(i.surname) + ", " + ContextBase.Decrypt(i.forname1) + " " + ContextBase.Decrypt(i.forname2);
else
employeeName = i.surname + ", " + i.forname1 + " " + i.forname2;
if (i.TrainingStartDate != new DateTime(1900, 1, 1))
employeeCPDRecords.Add(new EmployeeCPDReportRecord(employeeName, Convert.ToDateTime(i.StartDate), Convert.ToDateTime(i.EndDate), Convert.ToDecimal(i.CPDHours), Convert.ToDecimal(i.CPDPoints), i.Description,i.t,i.EndDate,Convert.ToDecimal(i.CPDHours),Convert.ToDecimal(i.CPDPoints),i.Description,"L&D"));
else
employeeCPDRecords.Add(new EmployeeCPDReportRecord(employeeName, Convert.ToDateTime(i.StartDate), Convert.ToDateTime(i.EndDate), Convert.ToDecimal(i.CPDHours), Convert.ToDecimal(i.CPDPoints), i.Description, i.StartDate, i.EndDate, Convert.ToDecimal(i.CPDHours), Convert.ToDecimal(i.CPDPoints), i.Description, "Employee CPD"));
});
}
List employeeCPDRecords=new List();
字符串employeeName;
var q=来自pamsEntities.EmployeeCPD中的cpd
来自pamsEntities中的traineeEvent.TrainingEvent受训人员
将员工e加入pamsEntities。cpd上的员工。员工ID等于e.emp_编号
在PamEntities中加入TrainingEventPart tEventPart。TrainingEventPart上的TrainingEventParts.TrainingEventPartId等于tEventPart.RecordId
其中(cpd.EmployeeID==id)和(startDate>=cpd.startDate和endDate 0 | | tEventPart.CPDPoints>0)
&&(cpd.cpd小时数>0 | | cpd.cpd点数>0)
||TraineEvent.StartDate>=开始日期
||TraineEvent.EndDate
{
if(ContextBase.encryptionEnabled)
employeeName=ContextBase.Decrypt(i.姓氏)+“,”+ContextBase.Decrypt(i.forname1)+“+ContextBase.Decrypt(i.forname2);
其他的
employeeName=i.姓氏+”,“+i.forname1+”+i.forname2;
如果(i.TrainingStartDate!=新日期时间(1900,1,1))
添加(新员工CPDReportRecords(员工姓名、转换.ToDateTime(i.StartDate)、转换.ToDateTime(i.EndDate)、转换.ToDecimal(i.CPDHours)、转换.ToDecimal(i.CPDPoints)、i.Description、i.t、i.EndDate、转换.ToDecimal(i.CPDHours)、转换.ToDecimal(i.CPDPoints)、i.Description,“L&D”);
其他的
employeeCPDRecords.Add(新EmployeeCPDReportRecord(employeeName,Convert.ToDateTime(i.StartDate),Convert.ToDateTime(i.EndDate),Convert.ToDecimal(i.CPDHours),Convert.ToDecimal(i.CPDPoints),i.Description,i.StartDate,i.EndDate,Convert.ToDecimal(i.CPDHours),i.Description,“员工CPD”);
});
}
使用此代码
List<EmployeeCPDReportRecord> employeeCPDRecords = new List<EmployeeCPDReportRecord>();
var q = ( from cpd in pamsEntities.EmployeeCPDs
from traineeEvent in pamsEntities.TrainingEventTrainees
join Employee e in pamsEntities.Employees on cpd.EmployeeID equals e.emp_no
join TrainingEventPart tEventPart in pamsEntities.TrainingEventParts on traineeEvent.TrainingEventPartId equals tEventPart.RecordId
where (cpd.EmployeeID == id) && (startDate >= cpd.StartDate && endDate <= cpd.EndDate) &&
(traineeEvent.EmployeeId == id)
&& (traineeEvent.TraineeStatus == 1 || traineeEvent.TraineeStatus == 2)
&& (tEventPart.CPDHours > 0 || tEventPart.CPDPoints > 0)
&& (cpd.CPDHours > 0 || cpd.CPDPoints > 0)
|| traineeEvent.StartDate >= startDate
|| traineeEvent.EndDate <= endDate
orderby cpd.StartDate
select new EmployeeCPDReportRecord
{
YourEmployeColumnName=(ContextBase.encryptionEnabled==true?ContextBase.Decrypt(e.surname) + ", " + ContextBase.Decrypt(e.forname1) + " " + ContextBase.Decrypt(e.forname2):e.surname + ", " + e.forname1 + " " + e.forname2),
YourEmployeeCPDColumnName=(i.TrainingStartDate !=new DateTime(1900, 1, 1)?"L&D":"Employee CPD")
surname = e.surname,
forname1 = e.forename1,
forname2 = e.forename2,
EmployeeID = cpd.EmployeeID,
StartDate = cpd.StartDate,
EndDate = cpd.EndDate,
CPDHours = cpd.CPDHours,
CPDPoints = cpd.CPDPoints,
Description = cpd.Description,
TrainingStartDate = tEventPart.StartDate,
TrainingEndDate = tEventPart.EndDate,
TrainingCPDHours = tEventPart.CPDHours,
TrainingCPDPoints = tEventPart.CPDPoints,
TrainingEventDescription = tEventPart.Description
}).ToList<EmployeeCPDReportRecord>();
List employeeCPDRecords=new List();
var q=(来自pamsEntities.EmployeeCPDs中的cpd)
来自pamsEntities中的traineeEvent.TrainingEvent受训人员
将员工e加入pamsEntities。cpd上的员工。员工ID等于e.emp_编号
在PamEntities中加入TrainingEventPart tEventPart。TrainingEventPart上的TrainingEventParts.TrainingEventPartId等于tEventPart.RecordId
其中(cpd.EmployeeID==id)和(startDate>=cpd.startDate和endDate 0 | | tEventPart.CPDPoints>0)
&&(cpd.cpd小时数>0 | | cpd.cpd点数>0)
||TraineEvent.StartDate>=开始日期
||TraineEvent.EndDate