Creating a Recent Hire WebPart using FullTextSQLQuery object and Linq (Part 3)

FILTERING ON RESULTS AND DATABINDING

 Previous Post

So in my previous post talked about how to retrieve UserProfiles but we are not done! we need to sort these user profiles and filter only the top 10 most receant. I also need to do some formating and databinding. Tha's what I'll discuss in this, of what I'm hoping is the last of my series.

 

Ok, So let's keep going! Now that I have my full set of results lets use something to filter the results...uhmm....what to use...HOW ABOUT LINQ!!?? As you can tell I'm on a huge Linq kick lately! SO let me explain what we're going to do. As you recall in my last post that the query.Execute() brought back a ResultTalbeCollection object. I will show you the next step to get a ResultTable object. Unfortunately we cannot use LInq right on the object becuase it is not strongly typed. This means that it has generic objects. It would be ideal if it retured a DataTable, or at least a set of DataTableRows. So what I did is used Generics and then applied Linq on that. First we need to create strongly typed object where we will store the user information we are after and because it is strongly typed it will be easily bindable to our SpGridView.

 

Nothing fancy here, Just a class to house our properties. Now let me show you the rest of the code.

Let me expalin some of this code. So after the results we got from query.Execute(), we check if ther is soemthing to do with results, then what I did was traverse through the ResultTable to get those user profiles into a List<UserInfo> list. The GetValue(index) is really the column that we are after. We created the query so we know what index referes to the column field we are after.

The most important part of this is the LINQ query in like 57. I was then able to order by descending order and then "Take(10)". I was almost there!!!!

 

Data Binding NEXT!!! Let's take a break and then I'll write a new Blog Post!!

 

 Next Post

Juan

Published Friday, November 28, 2008 5:59 PM by juanl

Comments

# Creating a Recent Hire WebPart using FullTextSQLQuery object and Linq (Part 4)

Friday, November 28, 2008 6:34 PM by Fringe SharePoint

DATA BINDING TO SPGRIDVIEW Previous Post So we're almost there. Previous posts, this is where we

# Links (11/30/2008) &laquo; Steve Pietrek - Everything SharePoint

Pingback from  Links (11/30/2008) « Steve Pietrek - Everything SharePoint

# Microsoft SharePoint and SQL Queries : Beyond Search

Tuesday, December 02, 2008 12:02 AM by Microsoft SharePoint and SQL Queries : Beyond Search

Pingback from  Microsoft SharePoint and SQL Queries : Beyond Search

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Powered by Community Server (Commercial Edition), by Telligent Systems