表达式树可能不包含动态操作 - linq

时间:2017-01-30 17:09:45

标签: c# linq

我有一个简单的查询,

            var RoundList = (from t1 in entities.RPlays.AsNoTracking()
                             where t1.Start.ToString("d") == "01/03/2017" && t1.VId == 32
                             select new
                             {
                                 TimePlayed = t1.TimePlayed,
                                 MatchPlayed = t1.MatchPlayed 
                             });

让我得到消息"表达式树可能不包含动态操作"但它并没有说出哪里:(

我在where行上遇到了问题。

我做错了什么?

1 个答案:

答案 0 :(得分:2)

这是由于DECLARE @loans TABLE ( LoanID INT , [Month] DATETIME , Rate DECIMAL(4, 2) , [Action] VARCHAR(10) ); INSERT @loans ( LoanID, Month, Rate, Action ) VALUES ( 1, '5/1/2000', 5.50, 'New ' ), ( 1, '9/1/2000', 6.00, 'Closed ' ), ( 2, '3/1/2000', 5.25, 'New ' ), ( 2, '5/2/2000', 5.50, 'Closed ' ); DECLARE @rates TABLE ( Month DATETIME , Rate DECIMAL(4, 2) ); INSERT @rates ( Month, Rate ) VALUES ( '1/1/2000', 5.00 ), ( '2/1/2000', 5.25 ), ( '3/1/2000', 5.25 ), ( '4/1/2000', 5.25 ), ( '5/1/2000', 5.50 ), ( '6/1/2000', 5.50 ), ( '7/1/2000', 5.50 ), ( '8/1/2000', 6.00 ), ( '9/1/2000', 6.00 ), ( '10/1/2000', 6.50 ); WITH loanStart AS ( SELECT * FROM @loans WHERE Action = 'New' ), loanEnd AS ( SELECT * FROM @loans WHERE Action = 'Closed' ), loanRanges ( loanId, lStart, lEnd ) AS ( SELECT ls.LoanID , ls.Month , le.Month FROM loanStart ls INNER JOIN loanEnd le ON ls.LoanID = le.LoanID ) SELECT lr.loanId , r.Month , r.Rate , COALESCE(ls.Action, le.Action) AS action FROM @rates r INNER JOIN loanRanges lr ON r.Month >= lr.lStart AND r.Month <= lr.lEnd LEFT JOIN loanStart ls ON ls.LoanID = lr.loanId AND YEAR(ls.Month) = YEAR(r.Month) AND MONTH(ls.Month) = MONTH(r.Month) LEFT JOIN loanEnd le ON le.LoanID = lr.loanId AND YEAR(le.Month) = YEAR(r.Month) AND MONTH(le.Month) = MONTH(r.Month) ORDER BY lr.loanId , r.Month;

您应该尝试比较这样的日期:

ToString("d")