我有以下课程:
df1 <- structure(list(Animal = 1:5, Date.1 = c("12/18/19", "12/18/19",
"12/18/19", NA, "12/18/19"), Weight.1 = c(55L, 64L, 75L, NA,
88L), Date.2 = c("1/2/20", "1/3/20", NA, "1/3/20", "1/6/20"),
Weight.2 = c(67L, 69L, NA, 85L, 86L), Date.3 = c(NA, "2/4/20",
NA, NA, "2/7/20"), Weight.3 = c(NA, 80L, NA, NA, 96L),
Date.4 = c("6/6/20",
NA, NA, NA, "6/6/20"), Weight.4 = c(101L, NA, NA, NA, 100L
)), class = "data.frame", row.names = c(NA, -5L))
我想做的是,加载一个public class Transfer
{
//some more properties
public virtual ICollection<TransferLineItem> TransferLineItem
}
public class TransferLineItem
{
public int EquipmentId { get; set; }
public virtual Equipment Equipment { get; set; }
}
,并将其链接到Transfer
集合中,并加载与该TransferLineItem
相关联的Equipment
。
我已将我的回购功能更改如下:
TransferLineItem
我尝试使用public virtual async Task<TEntity> GetOneAsync<TEntity>(
Expression<Func<TEntity, bool>> filter = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includes = null)
where TEntity : class
{
return await GetQueryable(filter: filter, includes: includes).SingleOrDefaultAsync();
}
protected virtual IQueryable<TEntity> GetQueryable<TEntity>(
Expression<Func<TEntity, bool>> filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
int? skip = null,
int? take = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includes = null)
where TEntity : class
{
IQueryable<TEntity> query = Context.Set<TEntity>();
if (includes != null)
{
query = includes(query); //includes.Aggregate(query, (current, include) => current.Include(include)).AsNoTracking();
}
if (filter != null)
{
query = query.Where(filter);
}
if (orderBy != null)
{
query = orderBy(query);
}
if (skip.HasValue)
{
query = query.Skip(skip.Value);
}
if (take.HasValue)
{
query = query.Take(take.Value);
}
return query;
}
如下调用上述函数。
ThenInclude()
认为这可行,但出现错误:
在Include中使用的Lambda表达式无效。
如何包含var primaryTransfer = await _repo.GetOneAsync<Transfer>(
filter: t => t.TransferId == transferId,
includes: source => source
.Include(t => t.TransferLink)
.Include(t => t.TransferLineItem)
.ThenInclude(t => t.Select(e => e.Equipment))
.Include(t => t.TransferScanItem)
.Include(t => t.TransferAggregate)
.Include(t => t.CompanyTransferType));
?