【发布时间】:2016-02-07 01:20:53
【问题描述】:
这是我尝试使用连接进行动态 Linq 查询。我尝试获取数据库中上次阅读时出现的独特类别、品牌和其他标准的列表。传递给查询的内容(品牌、类别等)只会在运行时定义。
我读到了使用 func、谓词等执行此操作的最佳方法,我认为这超出了我现阶段的能力。我正在尝试使用查询字符串更简单的方法,我正在为一些更简单的情况工作,但是我在加入时做错了。如果我只是用智能感知做简单的select product.Category,这当然可以,但不能在 select 子句中的字符串中。
public IEnumerable<string> getFilterItems(string dbColumn)
{
var filterItems = new List<string>();
return (from reading in Helper.LatestReadings
where reading.Distributor != Helper.Client
join product in Helper.Context.Products
on reading.ProductId equals product.SkuCode
select ("product." + dbColumn)).Distinct();
}
【问题讨论】: