问题描述
我写了一个非常简单的查询:
var locations = await _context.Locations
.Include(x => x.LocationsOfTheUsers)
.Include(x => x.Address)
.ThenInclude(x => x.County)
.Where(CalculateFilters(searchObj))
.ToListAsync(cancellationToken);
每次LocationsOfTheUsers
为空时,我决定.Include(x => x.LocationsOfTheUsers)
并按预期收到结果,但是由于这样定义,我不确定为什么必须包含此集合:
public class Location
{
public string Title { get; set; }
public long? RegionId { get; set; }
public Region Region { get; set; }
public long? AddressId { get; set; }
public Address Address { get; set; }
public long? CountyId { get; set; }
public County County { get; set; }
public ICollection<LocationsOfTheUsers> LocationsOfTheUsers { get; set; }
}
我认为它会自动包含在内,因为它在ICollection
类中以Location
的形式存在。
那么为什么这里需要.Include()
上的LocationsOfTheUsers
?
谢谢大家
欢呼
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)