tags:

views:

41

answers:

1

Here is a statement in SubSonic which does a find using the strongly typed column ProductId:

var products = Product.Find(x => x.ProductID <= 10);

Is there a way to not use a strongly typed column name and instead specify the column name with a string literal like so:

var columnName = "SampleColumn";
var products = Product.Find(x => x[columnName] <= 10);

Or something similar?

A: 

You can't do this with linq but you could do it using a fluent query as follows:

string columnName = "SampleColumn";

List<Product> products = new Select()
  .From<Product>()
  .Where(columnName).IsLessThanOrEqualTo(10)
  .ExecuteTypedList<Product>();
Adam