相关疑难解决方法(0)

在LINQ to EF查询中构建动态where子句

我正在尝试在LINQ查询中动态构建一个where子句,该查询通过EF引用表,但是我收到以下错误:

'ClaimantLastName' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near member access expression, line 6, column 2.
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试的:

string whereClause = string.Format("ClaimantLastName = '{0}' and ClaimantSSN = '{1}'", lastName, ssn);
Run Code Online (Sandbox Code Playgroud)

我也试过没有单引号无济于事.

这是实际的查询:

return db.Claims.Where(whereClause).Select(
                    u => new AdvancedSearchResult
                    {
                        ClaimNumber = u.ClaimNumber,
.
.
.
Run Code Online (Sandbox Code Playgroud)

我正在尝试做什么?这似乎很基本.我哪里错了?

更新:这是Claim实体.

public static Claim CreateClaim(global::System.Int32 id, global::System.String claimantFirstName, global::System.String claimantLastName, …
Run Code Online (Sandbox Code Playgroud)

linq entity-framework

2
推荐指数
2
解决办法
3万
查看次数

标签 统计

entity-framework ×1

linq ×1