exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 1 question 69 discussion

Actual exam question from Microsoft's 70-483
Question #: 69
Topic #: 1
[All 70-483 Questions]

You are developing an application that uses the Microsoft ADO.NET Entity Framework to retrieve order information from a Microsoft SQL Server database. The application includes the following code. (Line numbers are included for reference only.)

The application must meet the following requirements:
✑ Return only orders that have an OrderDate value other than null.
✑ Return only orders that were placed in the year specified in the year parameter.
You need to ensure that the application meets the requirements. Which code segment should you insert at line 08?

  • A. Option A
  • B. Option B
  • C. Option C
  • D. Option D
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
demoinq
Highly Voted 4 years, 6 months ago
The only working option is B. Tested with VS: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OrdersTest { class Program { public class Order : Object { public DateTime? OrderDate { get; set; } public override string ToString() { return this.OrderDate.ToString(); } } static List<Order> orders = new List<Order>() { new Order() { OrderDate = DateTime.Today }, new Order() { OrderDate = null }, new Order() { OrderDate = DateTime.Now } }; static void Main(string[] args) { var ord = from o in orders where o.OrderDate.HasValue && o.OrderDate.Value.Year == 2020 select o; foreach (Order o in ord) Console.WriteLine(o); Console.ReadLine(); } } }
upvoted 7 times
...
mendolf92
Highly Voted 5 years, 5 months ago
A will throw an exception it the nullable OrderDate is null!
upvoted 5 times
...
bleasdal3
Most Recent 5 years, 5 months ago
I don't agree. OrderDate is nullable but the year param isn't. Therefore when comparing values in the collection to something that can never be null, any null OrderDates will never satisfy the comparison. In my opinion you can just use A.
upvoted 1 times
FutureMfana
5 years, 5 months ago
And for real, option A is s shorthand for option B. Because once the value equals the year parameter, surely a value is assigned no need to check if the object has a value. Or if not equals to the year parameter, well, its not equal to the year, its not what we want or the object has no value
upvoted 2 times
justpassingexam
4 years, 10 months ago
you are not right. it just throws NullReferenceException
upvoted 3 times
...
TomasRafaj
4 years, 5 months ago
justpassingexam is right, you can't get the value of the object's property that is null
upvoted 1 times
...
...
FutureMfana
5 years, 5 months ago
The HasValue property returns true if the object has been assigned a value; if it has not been assigned any value or has been assigned a null value, it will return false.
upvoted 3 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...