Dear all,
I play with a mysql database using ADO entity framework (through devart dot.connect).
I get lists of entity objects (a) from listboxs and I would like to make a linq query retrieving all object from a given entity table (b) where there is a b foreign key:
//THIS WORKS :
IQueryable<Nb_student> nbstud = MainForm.context.Nb_student_set;
IQueryable<Cat_student> catstud = MainForm.context.Cat_student_set.Where(c => c.id == 2);
var test1 = from nb in nbstud
join bb in catstud on nb.cat_student_id equals bb.id
select nb;
=> this gives me only matching nb_students (this is what I want...)
Now, suppose instead of catstud, I have a list populated through a listbox.
IEnumerable<Cat_student> catstud2 = param_cat_students.AsEnumerable();
var ttt2 = from nb in nbstud
join bb in catstud2 on nb.cat_student_id equals bb.id
select nb;
=> it does't work, the error is the following: {"Unable to create a constant value of type 'System.Collections.Generic.IEnumerable`1'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."} it seems there is a problem with the ids (int32) for the join ???
More generally, my question is : In Linq to Entity, how to select items from a table matching various lists of criterias (lists are not knowed in advance since they are choosen by the users) without making lot of loops. I thougth Join was the solution, I also tried the .any and .contains syntaxes without success :
var tt3 = from nb in nbstud.Where
(nbx => catstud2.Any(cat => cat.id == nbx.cat_student_id)
select nb;
If you could advice me... This is I suppose a very common problem but I don't know how to proceed. Thanking you in advance,
Pierre