dahnealdo

dahnealdo

  • NA
  • 1
  • 1.7k

C# Linq Query Question

Nov 2 2010 8:25 PM

Good Evening everyone,

I've been trying to figure out the most efficient way to do this, but am falling short. Here's how it goes...

I am ultimately trying to determine "like customers" based on a specific customer's buying habits and a given threshold, say 50%. IE customer 1 purchased products A,B,C,D  ... customer 2 purchased B,C,D,E ... these two customers are >= 50% "likeness" so they should be matched.

My schema is as would be expected

CLIENT (1 ----- many)  CLIENT_PURCHASE (1 -------many) PRODUCT

*clientID                      *clientID *prodID                            *prodID


For now I am ignoring the threshold and simply am trying to find customers who have purchased any item within customer 1's history via a linq subquery. I think I have this working with the following two queries:


var clientOneHistory = (from cp in client.Client_Purchase                           
select cp.prodID).ToList();

  var matchedClients = (from cp in db.Client_Purchase
where clientOneHistory.Contains(cp.prodID)
select cp.Client.fullname).Distinct().ToList();


So my ultimate question is, "How do I work in the threshold portion?"

Thanks for your time

Answers (1)