【发布时间】:2015-08-06 16:15:18
【问题描述】:
我有这个查询,但在转换为 lambda 表达式时遇到问题
SELECT [dbo].[Prospects].[Id]
,[UserId]
,[NewId]
,[dbo].[Prospects].[Status]
FROM [dbo].[Prospects] join [dbo].[User] on [dbo].[User].Id = [dbo]. [Prospects].UserId
where [dbo].[Prospects].NewId = 3 and [dbo].[User].IsActive = 1
这是我得到的,但它不起作用
var result = Workspace.Prospects.Join
(Workspace.Users, pros => pros.UserId,
use => use.Id, (pros, use)
=> new { Prospect = pros, User = use}).Where
(both => both.User.IsActive == true && both.Prospect.NewId == idVacante)
.OrderBy(both => both.Prospect.Id).AsEnumerable().ToList();
List<Prospect> prospects = result.Cast<Prospect>().ToList();
【问题讨论】:
-
不工作怎么办?没有返回正确的结果?不编译?抛出异常?
-
抛出了哪个异常?或者它只是没有得到预期的行?
-
对不起,我不够具体,我没有得到预期的行。我需要正确选择字段。我收到这条消息 Test 'RecruitmentTestLab.TestLab.Prospects
.CheckProspectsVacancies' failed: System.InvalidCastException : Unable to cast object of type 'f__AnonymousType1`4[System.Int32,System.Int32,System.Int32,System. Int32]' 输入'RecruitmentTestLab.Prospect'。
标签: c# .net sql-server lambda