Using Dynamic Linq to set column name

235 Views Asked by At

I have a database that is a little inverted. For every project row, there are columns for different Engineers involved. (architect engineer, construction engineer, mechanical engineer). I need to get a list of projects that are assigned to one person. So to do that, I need to write a query that will search for their job title in the columns based on a drop down list. I am using Dynamic Linq and I have written a query like this

Dim db As New DesignConstructionDataContext
Dim query = db.all_drawings.Where("@0 = Kevin O'lausen", "ddlJobTitle.value").Select("ProjectNumber").toList

But when I run this, the eror I get says "=" is not compatible with string values. and when I try using "is" instead, it says it needs to be a boolean value. I am very green to this Dynamic linq thing, any help would be great!

1

There are 1 best solutions below

0
On

Methiks you a bit confused with linq.
So, as i understand

  1. you have field name in ddlJobTitle.value, and
  2. try check this field with value "Kevin O'lausen"

So you need change your query like

Dim query = db.all_drawings.Where(ddlJobTitle.value + " = @0", "Kevin O'lausen").Select("ProjectNumber").toList