工作,我有這個疑問,你可以在這裏看到:明顯不適合我的查詢C#LINQ
public IQueryable<ViewReportMaterialRequestContractor> ShowReport(int MRCId)
{
var q = from m in _ctx.MaterialRequestContractorDetails
where m.MaterialRequestContractorId == MRCId
join mat in _ctx.MaterialDescriptions on m.MaterialDescriptionId equals mat.Id
join l in _ctx.Lines on m.LineId equals l.Id
join joint in _ctx.Joints on m.LineId equals joint.LineId
join sheet in _ctx.Sheets on joint.SheetId equals sheet.Id
join testjoint in _ctx.TestPackageJoints on joint.Id equals testjoint.Id
join testpack in _ctx.TestPackages on testjoint.TestPackageId equals testpack.Id
select new ViewReportMaterialRequestContractor()
{
Id = m.Id,
ItemCode = mat.ItemCode,
LineNumber = l.LineNumber,
Description = mat.Description,
Size1 = mat.Size1.ToString(),
Size2 = mat.Size2.ToString(),
DocumentNumber = l.DocumentNumber,
};
return q;
}
我打電話給我的功能在UI
你可以看到:
List<ViewReportMaterialRequestContractor> lstMaterialRequestContractorDetails = _reportMaterialRequestContractorRepository.ShowReport(Id).ToList().Distinct().ToList();
我記錄重複4次,我有4個記錄重複4次,所以我有16個記錄,所以我必須使用不同的刪除重複的記錄。
但結果再次顯示16條記錄。爲什麼?
如何前'Distinct' –
刪除'ToList' @IvanStoev讓我查 –
@IvanStoev感謝它的工作原理,但是爲什麼呢?因爲我覺得不同的條款應被執行,因爲,我有之前不同, –