What is wrong with this code ?
I got this exception on the last line:
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.
var query = from colT in dal.TBL_Gharardad
select colT;
if(lstTarafeGharardadIds.Count>0)
query = from q in query
join id in lstTarafeGharardadIds on q.TarafeGharardadId equals id
select q;
dgvListeGharardad.DataSource = query.ToList();
The lastTarafeGharardadIds is a List<int>
I also test
dgvListeGharardad.DataSource = query;
Everything works well if if expression equals to false and this code
query = from q in query
join id in lstTarafeGharardadIds on q.TarafeGharardadId equals id
select q;
doesn’t run. But I can’t understand I got the error on the last line (on this code):
dgvListeGharardad.DataSource = query.ToList();
I think linq can’t join between an in-memory collection (lstTarafeGharardadIds) and a database table (dal.TBL_Gharardad, dal.v_Gharardad…).
Similar problem: Why won't this LINQ join statement work?
This should work: