c# - join list with linq-to-sql query -


i have list of myobject looks this:

public class myobject{   public int fruitid {get;set;}   public string fruitname {get;set;} }  list<myobject> thelist = new list<myobject>(); 

this list populated linq-to-sql query. i'm looking create join between list , table contains fruitid foreign key.

the table harvesttimes looks this:

fruitid   |   harvestdatetime  |   ripefactor    3      |        3/4/2011    |       2    3      |        4/5/2011    |       4    3      |        5/5/2011    |       3    4      |        3/21/2011   |       2    4      |        4/10/2011   |       2    4      |        5/10/2011   |       2 

this have far:

var thequery = (from list in thelist                 join fruit in mydc.harvesttimes on                 list.fruitid equals fruit.fruitid                 ....                 select new myobject{... }).tolist(); 

i'm have trouble clause. how fruit ripefactor 2. instance, fruit 3 has ripefactor of 2 has 4 , whereas fruit4 has 2s. tried contains both fruits come up.

thanks suggestions.

assuming there relationship between tables haversttime , fruit:

var thequery = mydc.harvesttimes     .where(p => thelist.select(q => q.fruitid).contains(p.fruitid))     .groupby(p => p.fruit)     .where(p => p.all(q => q.ripefactor == 2))     .select(p => p.key); 

this create ienumerable<fruit> think can converted myobject.

update: oops forgot add thelist.select(q => q.fruitid). that's why didn't compile. sorry =)

update2: same, considering ripefactor = 2 , 3

var thequery = mydc.harvesttimes     .where(p => thelist.select(q => q.fruitid).contains(p.fruitid))     .groupby(p => p.fruit)     .where(p => p.all(q => q.ripefactor == 2 || q.ripefactor == 3))     .select(p => p.key); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -