C# 将Dto与模型绑定,只返回一个Dto
首先看一下我的代码:这是C# 将Dto与模型绑定,只返回一个Dto,c#,linq,C#,Linq,首先看一下我的代码:这是ConceptDto: public Guid ConceptId { get; set; } public string ConceptName { get; set; } public string ConceptLatinName { get; set; } public List<ConceptSubDto> ConceptSubSidiary { get; set;} public Guid ConceptSubId { get; set;
ConceptDto
:
public Guid ConceptId { get; set; }
public string ConceptName { get; set; }
public string ConceptLatinName { get; set; }
public List<ConceptSubDto> ConceptSubSidiary { get; set;}
public Guid ConceptSubId { get; set; }
public string ConceptSubName { get; set; }
我有这样的域名
现在这是我的应用层,它有逻辑,我想通过id获取这些,并只返回一个ConceptDto
,但我不知道必须将这些DTO映射到域模型:
public async Task<ConceptManagementDto> GetConceptById(Guid id)
{
var concept = await _conceptManagementRepository.Query()
.Include(x => x.conceptSubSidiaries)
.GetOneAsync(x => x.Id == id);
return new ConceptManagementDto
{
ConceptManagementId = concept.Id,
ConceptName = concept.ConceptName,
ConceptLatinName = concept.ConceptLatinName,
ConceptSubSidiary = ??
};
}
公共异步任务GetConceptById(Guid id)
{
var concept=wait_conceptManagementRepository.Query()
.包括(x=>x.0)
.GetOneAsync(x=>x.Id==Id);
将新概念返回到ManagementDTO
{
ConceptManagementId=concept.Id,
ConceptName=concept.ConceptName,
concept拉丁名称=concept.concept拉丁名称,
概念子公司=??
};
}
如果DTO的字段较少,则此查询应有效: 公共异步任务GetConceptById(Guid id) { return wait_conceptManagementRepository.Query() .其中(x=>x.Id==Id) .选择(x=新概念管理数据到 { ConceptManagementId=x.Id, ConceptName=x.ConceptName, ConceptlationName=x.ConceptlationName, ConceptSubSidiary=x.ConceptSubSidiary .选择(sub=>newconceptsubdto { ConceptSubId=sub.ConceptSubId, ConceptSubName=sub.ConceptSubName }) 托利斯先生() }).First(); }