【发布时间】:2015-02-15 12:29:58
【问题描述】:
我有以下两个实体:
public class Artist
{
public int Id { get; set; }
public string FName { get; set; }
public string LName { get; set; }
public string UrlFriendly { get; set; }
public string ImgURL { get; set; }
public bool Verified { get; set; }
// relations
public virtual ICollection<Painting> Paintings { get; set; }
}
还有:
public class Painting
{
public int Id { get; set; }
public string Title { get; set; }
public string ImgUrl { get; set; }
public bool Verified { get; set; }
// relations
public int ArtistId { get; set; }
public virtual Artist Artist { get; set; }
}
然后在我的数据访问层,我有以下 LINQ:
public Artist GetArtistByUrlFriendly(string urlFriendly)
{
return _context
.Artists
.Include("Paintings")
.Where(a => a.Verified == true && a.Paintings.Any(p => p.Verified == true))
.FirstOrDefault(a => a.UrlFriendly == urlFriendly);
}
所以我想要一个特定的艺术家和他的画,但这个艺术家必须经过验证,他的画也必须经过验证。上面那个LINQ应该不行吧?
但事实并非如此!它也会返回未经验证的画作!知道为什么会这样吗?
【问题讨论】:
标签: c# linq ef-code-first