PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application that uses LINQ to SQL.
You create a data model name AdvWorksDataContext, and you add the Product table to the data model.
The Product table contains a decimal column named ListPrice and a string column named Color.
You need to update ListPrice column where the product color is Black or Red. Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
string[] colorList = new string[] {“Black”, “Red”};
AdvWorksDataContext dc = new AdvWorksDataContext();
var prod = from p in dc.Products
where colorList.Contains(p.Color)
select p;
foreach(var product in prod){
product.ListPrice = product.StandardCost * 1.5M;
}
dc.SubmitChanges();

B.
AdvWorksDataContext dc = new AdvWorksDataContext(“…”);
var prod = from p in dc.Products
select p;
var list = prod.ToList();
foreach(Product product in list){
if(product.Color == “Black, Red”){
product.ListPrice = product.StandardCost * 1.5M;
}
}
dc.SubmitChanges();

C.
AdvWorksDataContext dc = new AdvWorksDataContext(“…”);
var prod = from p in dc.Products
where p.Color == “Black, Red”
select p;
foreach(var product in prod){
product.ListPrice = product.StandardCost * 1.5M;
}
dc.SubmitChanges();

D.
AdvWorksDataContext dc = new AdvWorksDataContext(“…”);
var prod = from p in dc.Products
select p;
var list = prod.ToList();
foreach(Product product in list){
if((product.Color == “Black) && (product.Color == “Red”)){
product.ListPrice = product.StandardCost * 1.5M;
}
}
dc.SubmitChanges();


Leave a Reply