I have a simple case, I need to join two tables and filter the records by my in-code prepared list.
Example :
<code>var select = db.Table table1
join db.Table2 table2 on table1.FK equals table2.FK
where myList.Any(x => x.Key == table1.ColumnName && x.Value== table2.ColumnName)
select new {table1.ColumnName, table2.ColumnName}
var result = select.ToList();
</code>
<code>var select = db.Table table1
join db.Table2 table2 on table1.FK equals table2.FK
where myList.Any(x => x.Key == table1.ColumnName && x.Value== table2.ColumnName)
select new {table1.ColumnName, table2.ColumnName}
var result = select.ToList();
</code>
var select = db.Table table1
join db.Table2 table2 on table1.FK equals table2.FK
where myList.Any(x => x.Key == table1.ColumnName && x.Value== table2.ColumnName)
select new {table1.ColumnName, table2.ColumnName}
var result = select.ToList();
myList is a List<KeyValuePair<string,string>>.
The error im getting is ‘Sequence value table1.myList’ cannot be Converted to SQL.
I tried using class instead of KeyValuePairs, changing Any()
method to Exists()
or even
Count() > 1
but none of it worked.
If I pass the names as string, it works perfectly fine.
Example Working code
<code>var select = db.Table table1
join db.Table2 table2 on table1.FK equals table2.FK
where table1.ColumnName == '...' && table2.ColumnName == '...'
select new {table1.ColumnName, table2.ColumnName}
</code>
<code>var select = db.Table table1
join db.Table2 table2 on table1.FK equals table2.FK
where table1.ColumnName == '...' && table2.ColumnName == '...'
select new {table1.ColumnName, table2.ColumnName}
</code>
var select = db.Table table1
join db.Table2 table2 on table1.FK equals table2.FK
where table1.ColumnName == '...' && table2.ColumnName == '...'
select new {table1.ColumnName, table2.ColumnName}
New contributor
jak co is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.