【发布时间】:2021-02-19 11:32:30
【问题描述】:
我是 LINQ 的新手,但遇到了问题。
我在两个不同的 dbContext(userContext 和 mailContext)中有两个表。在将此数据添加到 UserMail 表后,我想从 UserAccount 表中选择一部分数据。 UserAccount 表有很多列,而 UserMail 表有 4 列(CreatedDate、UserAccountId、UserType、ItemCount)
选择代码:
var selectedUsers = _userContext.UserAccount
.Where(x=>x.Created == new DateTime(2021, 02, 17))
.Select(x => new UserMail()
{
CreatedDate = x.Created,
UserAccountId = x.AccountId,
UserType = x.UserType,
ItemCount = (int?)x.ItemCount,
}).ToList();
查询返回 null,selectedUsers 的计数=0。我从 SQL 中检查,一些数据退出,我错过了查询中的一点吗?
实际上,我需要按 AccountId 和 CreatedDate 分组的 ItemCount 的总和,但首先,我想得到这个查询的结果。
【问题讨论】:
标签: linq sql-to-linq-conversion