What should you do?

You create a Web Part.

The Web Part contains a grid view named GridView1 and the following code segment. (Line numbers are included for reference only.)

01 IntranetDataContext dc = new IntranetDataContext(“http://intranet”);
02 MyGridView.DataSource = from announce In dc.Announcements _ ;
03
04 Select announce IntranetDataContext is a LINQ context.

You need to ensure that GridView1 only displays items from Announcements that have an expiry date that is greater than or equal to the current date.

What should you do?

You create a Web Part.

The Web Part contains a grid view named GridView1 and the following code segment. (Line numbers are included for reference only.)

01 IntranetDataContext dc = new IntranetDataContext(“http://intranet”);
02 MyGridView.DataSource = from announce In dc.Announcements _ ;
03
04 Select announce IntranetDataContext is a LINQ context.

You need to ensure that GridView1 only displays items from Announcements that have an expiry date that is greater than or equal to the current date.

What should you do?

A.
Change line 04 to the following code segment:
Select Not announce.Expires.HasValue

B.
Change line 04 to the following code segment:
Select announce.Expires.Value.CompareTo(DateTime.Now) >= 0

C.
Add the following line of code at line 03:
Where announce.Expires.Value.CompareTo(DateTime.Now) >= 0 _

D.
Add the following line of code at line 03:
Order By announce.Expires.Value.CompareTo(DateTime.Now) >= 0 _

Explanation:
MNEMONIC RULE: “only WHERE is missing”

Just remember the order of LINQ query: FROM – WHERE – SELECT

Using LINQ to SharePoint
http://msdn.microsoft.com/en-us/library/ee535491.aspx



Leave a Reply 0

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