我之前也有类似的帖子,但是我意识到我在问一个错误的问题。
我有几个联接的查询。我正在尝试添加Where(x => x.y.Code == x.x.VariableColumn)
(请参见下面的historyCode)`
我有此代码:
var query = db.HistoryData
.Join(db.Calendars, x => x.EventId, x => x.EventId, (x, y) => new { x, y.CompanyId })
.Join(db.JobData, x => x.CompanyId, x => x.CompanyId, (x, y) => new { x.x, y })
.Where(x => x.x.CompanyId == companyId && x.y.JobLevel == levelNumber);
var historyParameter = Expression.Parameter(typeof(HistoryData), "hist");
var historyCode = Expression.Property(historyParameter, $"field{levelNumber}");
var jobParameter = Expression.Parameter(typeof(JobData), "job");
var jobCode = Expression.Property(jobParameter, "code");
var operation = Expression.Equal(jobCode, historyCode);
var filterCondition = Expression.Lambda<Func<string, bool>>(operation, new[] { jobParameter, historyParameter });
当我转到filterCondition
的分配时,我不知道如何表达Type(我有“ string”,但是我需要一个匿名类型,该匿名类型具有来自联接的HistoryData和JobData。