Web Developer Framework 4.0 Sample Questions – 24

Question: You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server 2008 database. You create classes by using LINQ to SQL based on the records shown in the You need to create a LINQ query to retrieve a list of objects that contains the OrderID and CustomerID properties. You need to retrieve the total price amount of each Order record. What are two possible ways to achieve this goal (Each correct answer presents a complete solution. Choose two.)

  1. from details in dataContext.Order_Detail
    group details by details.OrderID into g
    join order in dataContext.Orders on g.Key equals order.OrderID
    select new {
    OrderID = order.OrderID, CustomerID = order.CustomerID,
    TotalAmount = g.Sum(od => od.UnitPrice * od.Quantity)
    }
  2. dataContext.Order_Detail.GroupJoin(dataContext.Orders,
    d => d.OrderID,
    o => o.OrderID,
    (dts, ord) => new {
    OrderID = dts.OrderID,
    CustomerID = dts.Order.CustomerID,
    TotalAmount = dts.UnitPrice * dts.Quantity
    }
    )
    from order in dataContext.Orders
    group order by order.OrderID into g
  3. join details in dataContext.Order_Detail on g.Key equals details.OrderID
    select new {
    OrderID = details.OrderID,
    CustomerID = details.Order.CustomerID,
    TotalAmount = details.UnitPrice * details.Quantity
    }
  4. dataContext.Orders.GroupJoin(dataContext.Order_Detail,
    o => o.OrderID,
    d => d.OrderID,
    (ord, dts) => new {
    OrderID = ord.OrderID,
    CustomerID = ord.CustomerID,
    TotalAmount = dts.Sum(od => od.UnitPrice * od.Quantity)
    }
    )

Correct Answer: 1 & 4


Question: You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. You create the classes shown in the following exhibit. You add the following code segment to the application. (Line numbers are included for reference only.
01 public void QueryPlayers(List <League> leagues) {
02
03 }
You create a LINQ query to retrieve a collection of Player objects. You need to ensure that the collection includes all the players from each team and every league. Which code segment should you insert at line 02

  1. var query = leagues.Select(l => l.Teams.Select(t => t.Players));
  2. var query = leagues.Select(l => l.Teams.SelectMany(t => t.Players));
  3. var query = leagues.SelectMany(l => l.Teams.SelectMany(t => t.Players));
  4. var query = leagues.SelectMany(l => l.Teams.Select(t => t.Players));

Correct Answer: 3


Question: You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to create an application. The application connects to a Microsoft SQL Server database. You create the classes shown in the following exhibit. You add the following code segment to the application. (Line numbers are included for reference only.)
01 Public Sub QueryPlayers(leagues As List(Of League))
02
03 End Sub
You create a LINQ query to retrieve a collection of Player objects. You need to ensure that the collection includes all the players from each team and every league. Which code segment should you insert at line 02

  1. Dim query As var = leagues.[Select](Function(l As ) l.Teams.[Select](Function(t As ) t.Players))
  2. Dim query As var = leagues.[Select](Function(l As ) l.Teams.SelectMany(Function(t As ) t.Players))
  3. Dim query As var = leagues.SelectMany(Function(l As ) l.Teams.SelectMany(Function(t As ) t.Players))
  4. Dim query As var = leagues.SelectMany(Function(l As ) l.Teams.[Select](Function(t As ) t.Players))

Correct Answer: 3


Question: You are consuming a Windows Communication Foundation (WCF) service in an ASP.NET Web application. The service interface is defined as follows.
[ServiceContract]
public interface ICatalog
{
[OperationContract]
[WebGet(UriTemplate = "/Catalog/Items/{id}", ResponseFormat = WebMessageFormat.Json)]
string RetrieveItemDescription(int id);
}

The service is hosted at /Catalog.svc.
You need to call the service using jQuery to retrieve the description of an item as indicated by a variable named itemId. Which code segment should you use

  1. $.get(String.format("/Catalog.svc/Catalog/Items/ id={0}", itemId) null, function (data) {
    ...
    }, "javascript");
  2. $.get(String.format("/Catalog.svc/Catalog/Items/{0}", itemId), null, function (data) {
    ...
    }, "json");
  3. $.get(String.format("/Catalog.svc/Catalog/Items/{0}", itemId), null, function (data) {
    ...
    }, "xml");
  4. $.get(String.format("/Catalog.svc/Catalog/Items/id={0}", itemId), null, function (data) {
    ...
    }, "json");

Correct Answer: 2


Question: You are developing an application to update a user’s social status. You need to consume the service using Windows Communication Foundation (WCF).
The client configuration is as follows.
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="SocialConfig">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"
realm="Social API" />
</security>
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address="http://contoso.com"
binding="webHttpBinding"
bindingConfiguration="SocialConfig"
contract="ISocialStatus"
name="SocialClient" />
</client>
</system.serviceModel>
The service contract is defined as follows.
[ServiceContract]
public interface ISocialStatus
{
[OperationContract]
[WebInvoke(UriTemplate =
"/statuses/update.xml status={text}")]
void UpdateStatus(string text);
}

Which code segment should you use to update the social status

  1. using (WebChannelFactory<ISocialStatus> factory = new WebChannelFactory<ISocialStatus>("SocialClient"))
    {
    factory.Credentials.UserName.UserName = user.Name;
    factory.Credentials.UserName.Password = user.Password;
    ISocialStatus socialChannel = factory.CreateChannel();
    socialChannel.UpdateStatus(newStatus);
    }
  2. using (ChannelFactory<ISocialStatus> factory = new WebChannelFactory<ISocialStatus>(typeof(ISocialStatus)))
    {
    factory.Credentials.UserName.UserName = user.Name;
    factory.Credentials.UserName.Password = user.Password;
    ISocialStatus socialChannel = factory.CreateChannel();
    socialChannel.UpdateStatus(newStatus);
    }
  3. using (ChannelFactory<ISocialStatus> factory = new ChannelFactory<ISocialStatus>("POST"))
    {
    factory.Credentials.Windows.ClientCredential.UserName =
    user.Name;
    factory.Credentials.Windows.ClientCredential.SecurePassword.
    SetAt(0, Convert.ToChar(user.Password));
    ISocialStatus socialChannel = factory.CreateChannel();
    socialChannel.UpdateStatus(newStatus);
    }
  4. using (WebChannelFactory<ISocialStatus> factory = new WebChannelFactory<ISocialStatus>(typeof(ISocialClient)))
    {
    factory.Credentials.Windows.ClientCredential.UserName =
    user.Name;
    factory.Credentials.Windows.ClientCredential.SecurePassword.
    SetAt(0, Convert.ToChar(user.Password));
    ISocialStatus socialChannel = factory.CreateChannel();
    socialChannel.UpdateStatus(newStatus);
    }

Correct Answer: 1

Tagged . Bookmark the permalink.

Leave a Reply