Community
Showing results for 
Search instead for 
Do you mean 
Reply

Would LINQ be an easier method to filtering Histories, etc than using IFilterCriteria?

Accepted Solution Solved
Copper Contributor
Posts: 123
Country: Canada
Accepted Solution

Would LINQ be an easier method to filtering Histories, etc than using IFilterCriteria?

Hey everyone,

I'm still fairly new with working with the SDK and development in general but I have always found filtering lists of Activities or Histories somewhat difficult or confusing. 

I just learned about using Generic Lists and LINQ and wondered if there was any reason not to use it as apposed to the IFilterCriteria when getting a list of Histories to filter.

Here is an example of how I would use it to get a list of historytypes on a contact which are associated with a specific custome activity type:

// I will use my contact as an example
Contact c = tool.ActFwk.CurrentUser.Contact;

// Get the custom activity type for which I want to get the HistoryTypes associated to
ActivityType cfActivityType = tool.ActFwk.Activities.GetActivityType("Client Follow-up");

// Get the history types associated to the custome activity type
HistoryType[] hTypes = tool.ActFwk.Histories.GetHistoryTypes(cfActivityType); // Get all of the histories associated to the contact
HistoryList hL = tool.ActFwk.Histories.GetHistories(null, c);
// Create a new generic list of type History
List<History> list = new List<History>();
// Loop through the historyList and add them to the generic list
foreach (History h in hL)
{ list.Add(h); }

// Use LINQ to make a new list with specific criteria and sorted by create date List<History> followupHistories = list.Where(
h => h.Regarding == "Follow-up on Documents Sent" &&
hTypes.Contains(h.HistoryType)).OrderByDescending(h => h.CreateDate).ToList();
// output information from the first History in the list which was the last created
Console.WriteLine(followupHistories[0].CreateDate.ToString() + " " + followupHistories[0].Details);

// output the count of histories that meet the criteria Console.WriteLine(followupHistories.Count.ToString());

 
I guess my question is are there any negative imacts to doing this which i find far easier rather than trying to decypher how the filterCriteria works.  I imagine there may be more memory resources being used with this method? 

Any help or pointers for this rookie would be greatly appreciated!

Thanks!
-Eric


Accepted Solutions
Solution
Accepted by topic author e_hoog
‎09-25-2015 03:20 AM
Nickel Contributor
Posts: 175
Country: USA

Re: Would LINQ be an easier method to filtering Histories, etc than using IFilterCriteria?

Overall, it depends on the situation as to which is better. I'd suggest trying both methods and looking at the differences (speed, RAM usage, etc.), but my guess is the LINQ method will be slower and use more RAM.

In one instance for me, getting all the data and using LINQ was much worse for performance. The situation: I have a set of three queries, each with a dynamic SQL statement using PIVOT. To run each query and display the results on an ASP.NET page takes about 30 seconds. To try and improve that time, I tried using LINQ with all of the data, to filter and pivot to get the same results. I was able to get the proper results, but it took about 3 times as long.

YMMV

View solution in original post


All Replies
Solution
Accepted by topic author e_hoog
‎09-25-2015 03:20 AM
Nickel Contributor
Posts: 175
Country: USA

Re: Would LINQ be an easier method to filtering Histories, etc than using IFilterCriteria?

Overall, it depends on the situation as to which is better. I'd suggest trying both methods and looking at the differences (speed, RAM usage, etc.), but my guess is the LINQ method will be slower and use more RAM.

In one instance for me, getting all the data and using LINQ was much worse for performance. The situation: I have a set of three queries, each with a dynamic SQL statement using PIVOT. To run each query and display the results on an ASP.NET page takes about 30 seconds. To try and improve that time, I tried using LINQ with all of the data, to filter and pivot to get the same results. I was able to get the proper results, but it took about 3 times as long.

YMMV
Copper Contributor
Posts: 123
Country: Canada

Re: Would LINQ be an easier method to filtering Histories, etc than using IFilterCriteria?

Thanks for your response.  I will definitely keep these things in mind going forward.

I still have a lot to learn!

Cheers,
-Eric