Which of the following queries should you use?

You need to write a LINQ query that can be used against a ContosoEntities context object named context to find all
parts that have a duplicate name. Which of the following queries should you use?
(Each correct answer presents a complete solution. Choose two).

You need to write a LINQ query that can be used against a ContosoEntities context object named context to find all
parts that have a duplicate name. Which of the following queries should you use?
(Each correct answer presents a complete solution. Choose two).

A.
context.Parts.Any(p => context.Parts.Any(q => p.Name == q.Name));

B.
context.Parts.GroupBy(p => p.Name).Where(g => g.Count() > 1).SelectMany(x => x);

C.
context.Parts.SelectMany(p => context.Parts.Select(q => p.Name == q.Name && p.Id != q.Id));

D.
context.Parts.Where(p => context.Parts.Any(q => q.Name == p.Name && p.Id != q.Id);



Leave a Reply 1

Your email address will not be published. Required fields are marked *


John Galt

John Galt

Verified the answer using Visual Studio.