我有两个实体类,称为 AccountEntity 和 ProjectEntitiesEntity。 AccountEntity 由三个实体组成:
public class AccountEntity : BaseEntity
{
public long AccountNumber { get; set; }
public AccountTypeEnum AccountType { get; set; }
public bool Privacy { get; set; }
}
ProjectEntitiesEntity 类由以下实体组成:
public class ProjectEntitiesEntity : BaseEntity
{
public string Name { get; set; }
public ProjectEntitiesEnum Type { get; set; }
public bool Status { get; set; }
}
所以,我想要一个 api,它可以从分页形式组合的表中返回数据。这是我迄今为止尝试过的代码:
public async Task <PaginatedList<AccountVM>> GetProjectEntitiesList(DataParameters parameters)
{
var pageIndex = parameters?.PageNumber ?? 1;
var pageSize = parameters?.PageSize ?? 1;
var accQueryList = _context.ProjectEntities.Include(k => k.ContactAddress).OrderByDescending(x => x.CreatedDate).Where(x => true);
var acc = _context.Accounts.Include(x => x.AccountManagerAddress).OrderByDescending(x => x.CreatedDate).Where(x => x.AccountType==AccountTypeEnum.ProjectProponent);
//dynamic obj3 = accQueryList.Union(acc);
var result = accQueryList.AsEnumerable().Concat<object>(acc.AsEnumerable()).ToList();
//var tp = acc.GetType();
//Console.WriteLine(result);
var count = await accQueryList.CountAsync();
//List with paging
//var items = _mapper.Map<List<ProjectEntitiesDto>>(await accQueryList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync());
//Check if Account KYC is added and submitted
var returnView = new PaginatedResponseVM<ProjectEntitiesDto>(count, items);
return returnView;
}
是的,我在映射器中使用 ProjectEntitesDto 文件,问题是它只会从 ProjectEntities 表返回数据,而不是从 Account 表返回数据。如果我使用 AccountDto 那么它只会返回帐户表中的数据。我想我也必须合并 Dto 文件,但不知道如何实现它。
那么,有人可以解释一下吗?任何帮助都将非常感激。