Linq sql-我应该将带“的短语放在哪里?”;其中;
这是我的问题,一个几乎有效的问题。我需要在这个查询中添加“where(k.IdUser==d.UserDoc。 添加此项时会出现问题。无论我将此项放在何处,它都会停止工作。此处没有“加入”选项。Linq sql-我应该将带“的短语放在哪里?”;其中;,linq,Linq,这是我的问题,一个几乎有效的问题。我需要在这个查询中添加“where(k.IdUser==d.UserDoc。 添加此项时会出现问题。无论我将此项放在何处,它都会停止工作。此处没有“加入”选项。 var documents = (from d in DocumentDAO.GetDocument() from k in UserDAO.GetUsers() where (DateTime.Now
var documents = (from d in DocumentDAO.GetDocument()
from k in UserDAO.GetUsers()
where (DateTime.Now <= d.ExpirationDate)
select new DocumentUI
{
Title = d.Title,
Description = d.Description,
DateOfAdd = d.DateOfAdd,
ExpirationDate = d.ExpirationDate,
UserDoc = d.UserDoc,
User = new UserUI {
FirstName = k.FirstName,
LastName = k.LastName}
}).ToList();
下面的查询(与您的第一个查询相同)应该返回
列表
,前提是您有满足的适当数据((DateTime.Now,难道不可能没有IdUser
等于d.UserDoc
?:)不,在数据库中,我有一些字段,如title、description,其中一个字段是who add,它不是NULL,我检查它,有用户IDPerhaps,请尝试放置UserDAO.GetUsers()
首先在一个单独的、具体化的集合中,然后使用调试器查看,以验证在代码到达这里的那一刻,是否确实检索到了该用户。我尝试了,没有任何更改。它不应该更改任何内容。它应该向您提供我写过的信息。那么,您发现了什么?正如我所说的,join不是和option(我的任务要求它),此外,我只是尝试了一下,它不会改变它
var documents = (from d in DocumentDAO.GetDocument()
from k in UserDAO.GetUsers()
where ((DateTime.Now <= d.ExpirationDate) && (d.UserDoc == k.IdUser))
select new DocumentUI
{
Title = d.Title,
Description = d.Description,
DateOfAdd = d.DateOfAdd,
ExpirationDate = d.ExpirationDate,
UserDoc = d.UserDoc,
User = new UserUI {
FirstName = k.FirstName,
LastName = k.LastName}
}).ToList();
var documents = (from d in DocumentDAO.GetDocument()
from k in UserDAO.GetUsers().Where(k => k.IdUser == d.UserDoc)
where (DateTime.Now <= d.ExpirationDate)
select new DocumentUI
{
Title = d.Title,
Description = d.Description,
DateOfAdd = d.DateOfAdd,
ExpirationDate = d.ExpirationDate,
UserDoc = d.UserDoc,
User = new UserUI {
FirstName = k.FirstName,
LastName = k.LastName}
}).ToList();
public class DocumentUI
{
public string Title { get; set; }
public string Description { get; set; }
public DateTime DateOfAdd { get; set; }
public DateTime ExpirationDate { get; set; }
public int UserDoc { get; set; }
public UserUI User { get; set; }
}
var documents = (from d in DocumentDAO.GetDocument()
join k in UserDAO.GetUsers()
on d.UserDoc equals k.IdUser
where (d.ExpirationDate >= DateTime.Now)
select new DocumentUI
{
Title = d.Title,
Description = d.Description,
DateOfAdd = d.DateOfAdd,
ExpirationDate = d.ExpirationDate,
UserDoc = d.UserDoc,
User = new UserUI {
FirstName = k.FirstName,
LastName = k.LastName}
}).ToList();