0
dfielec created
Hello in Asp.net Zero Core & Angulare v4.5.1 .net Core 2.0 solution, AutoMapper Flattering dont work.
thanks in advance.
8 Answer(s)
-
0
In reality, the repository gives bad results. here an example
public class Parent: FullAuditedEntity { [Required] public virtual string Name { get; set; } public virtual ICollection<Child> Children{ get; set; } }
public class Child: FullAuditedEntity { [ForeignKey("ParentId")] public virtual Parent Parent{ get; set; } [Required] public virtual int ParentId { get; set; } public virtual string Name { get; set; } }
[AutoMapFrom(typeof(Parent))] public classChildDto : FullAuditedEntityDto { public string Name { get; set; } public int ParentId { get; set; } public string ParentName { get; set; } }
public class ChildAppService : MyAppServiceBase, IChildAppService { private readonly IRepository<Child> _childRepository; public ChildAppService(IRepository<Child> childRepository) { _childRepository = childRepository; } public async Task<ListResultDto<ParentDto>> GetChildren() { var children= await _childRepository.GetAllListAsync(); return new ListResultDto<ChildDto>(ObjectMapper.Map<List<ChildDto>>(children)); } }
in the children list, the children[i].Parent is always null
-
0
EntityFrameworkCore requires eager-loading:
var children = await _childRepository.GetAllIncluding(c => c.Parent).ToListAsync();
-
0
Thank you very much aaroon, it works.
Now, how to add multiple attributes?
-
0
<cite>DFIELEC: </cite> Thank you very much aaroon, it works.
Now, how to add multiple attributes?
var children = await _childRepository .GetAllIncluding(c => c.FirstParent) .Include(c => c.SecondParent) .ToListAsync();
-
0
GetAllIncluding accepts params, so simply use one or more commas:
var children = await _childRepository .GetAllIncluding( c => c.Parent, c => c.AnotherRelationship) .ToListAsync();
-
0
Thank you very much
-
0
So does this mean that extending AsyncCrudAppService won't work as expected? I mean, it won't include nested collections?
-
0
As explained above, EntityFrameworkCore requires eager-loading.