Net core 和 efcore db 第一种方法。我有两张桌子。第一个表是 SiteDetails,它包含与 Sitedetails 相关的列,它根据主键和外键关系引用其他表国家。现在我想将这些国家也包括在内作为结果的一部分。下面是我的通用方法。
public async Task<IEnumerable<T>> GetAsync(Expression<Func<T, bool>> filter = null, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null, params Expression<Func<T, object>>[] includes)
{
IQueryable<T> query = this.dbSet;
foreach (Expression<Func<T, object>> include in includes)
{
query = query.Include(include);
}
if (filter != null)
{
query = query.Where(filter);
}
if (orderBy != null)
{
query = orderBy(query);
}
return await query.ToListAsync().ConfigureAwait(false);
}
在下面的代码中,我调用了上面的方法
var siteDetails= await this.siteDetailsRepository.GetAsync(x => x.siteNo== siteNo , source => source.Include(???)).ConfigureAwait(false);
下面是 siteDetails 页面 Country 表 SitDetails 有字段 siteNo, siteName, CountryId 的关系 Country 有字段 CountryId 和 CountryName
有人可以帮我在这里写包含语法吗?任何帮助,将不胜感激。谢谢