70-680 Sybex, 70-680 Study

January 14th, 2012

QUESTION NO: 69

The database contains orphaned Color records that are no longer connected to Part records.

You need to clean up the orphaned records. You have an existing ContosoEntities context object named context.

Which code segment should you use?

A. context.Colors.ToList().RemoveAll(c => !c.Parts.Any()); context.SaveChanges();

B. var unusedColors = context.Colors.Where(c => !c.Parts.Any()).ToList(); foreach (var unused in unusedColors) context.DeleteObject(unused); context.SaveChanges();

C. var unusedColors = context.Colors.Where(c => !c.Parts.Any());
context.DeleteObject(unusedColors); context.SaveChanges();

D. context.Colors.TakeWhile(c => !c.Parts.Any()); context.SaveChanges();

Answer: B
Explanation:

71

QUESTION NO: 70

The application must provide a component part list for any product. The component part list must give the quantity of each distinct part that is required to manufacture that product. You need to create a LINQ expression that delivers a result of type IEnumerable> to meet the requirements. Which expression should you use?

A. IEnumerable < Tuple < int , Part>> result = part.Descendants
. GroupBy (p => p)
.Select(g => Tuple.Create ( g.Count (), g.Key ));

B. IEnumerable < Tuple < int , Part>> result = part.Descendants
. ToDictionary (c => c)
.Select(d => Tuple.Create ( d.Value.Children.Count (), d.Key ));

C. IEnumerable < Tuple < int , Part>> result = part.Children
. GroupBy (p => p)
.Select(g => Tuple.Create ( g.Count (), g.Key ));

D. IEnumerable < Tuple < int , Part>> result = part.Children
.Distinct()
. GroupBy (p => p)
.Select(g => Tuple.Create ( g.Count (), g.Key ));

E. IEnumerable < Tuple < int , Part>> result = part.Descendants
.Distinct()
. GroupBy (p => p) .Select(g => Tuple.Create ( g.Count (), g.Key ));

Answer: D
Explanation:

QUESTION NO: 71

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.Where(p => context.Parts.Any(q => q.Name == p.Name && p.Id != q.Id));

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

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

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

Answer: A,B
Explanation:

Both comments and pings are currently closed.