我有这个查询
var q = from internalMaterialIssueVocherDetail in _ctx.InternalMaterialIssueVoucherDetails
where internalMaterialIssueVocherDetail.InternalMaterialIssueVoucherId == Id
join line in _ctx.Lines on internalMaterialIssueVocherDetail.LineId equals line.Id
join material in _ctx.Materials on line.Id equals material.LineId
我在InternalMaterialIssueVoucherDetails
中有1条记录,此表与使用material
的{{1}}有关系。在我的Lines
表中,我有20条记录,输出重复20次,值相同。
为什么呢?我该如何解决?
这是主要查询
material
答案 0 :(得分:1)
您可以使用Distinct
删除重复项:
(from ........
select new
{
ItemCode = materialDescription.ItemCode,
MaterialDescription = materialDescription.Description,
SheetNumber = sheet.SheetNumber,
LineNumber = line.LineNumber,
TestPackageNumber = testPackage.PackageNumber,
QuantityDeliverToMember = internalMaterialIssueVocherDetail.QuantityDeliverToMember.ToString(),
Size = materialDescription.Size1
}).Distinct().Select(x => new ViewIMIV()
{
ItemCode = x.ItemCode,
MaterialDescription = x.MaterialDescription,
SheetNumber = x.SheetNumber,
LineNumber = x.LineNumber,
TestPackageNumber = x.TestPackageNumber,
QuantityDeliverToMember = x.QuantityDeliverToMember,
Size = x.Size
}).ToList();