Base solution for your next web application

Activities of "klawsuc"

Another update. Have an icollection of entities does not work with the dto. Not sure why but I get the error "net::ERR_CONNECTION_RESET". As well as a debug message in browser console (assuming from angular) that "Content-Type is not sent!". Sometimes I can open the api link and get the data...other times I get redirected to <a class="postlink" href="http://localhost:22742/Account/Login?ReturnUrl=%2Fapi%2Fservices%2Fapp%2FForm%2FGetFormShow%3FId%3D1">http://localhost:22742/Account/Login?Re ... w%3FId%3D1</a>

Maybe also worth mentioning that I am using the Core + Angular 4.1.1 version.

In case anyone else runs into this issue: <a class="postlink" href="https://github.com/aspnet/EntityFrameworkCore/issues/6560#issuecomment-248749588">https://github.com/aspnet/EntityFramewo ... -248749588</a> I was trying to use ThenInclude but wasn't getting the intellisense.

However I am still faced with the issue of how to get the nested data into their appropriate dtos. Or am I left with one of the following: for nested data, they can't be in their own dto but rather lazy loaded into the parent dto...in this case PersonViewDto would have a collection of Pet entities which in turn has lazy loaded Toy entities. I would end up with all the columns for pets and toys. run separate queries to get the data into four different dtos.

Any other options?

Question

I want to return a Dto that has data from nested related tables (not sure how else to word this). Here is a sample of what the structure would look like:

  • Household (only one)
  • People (one or more that belong to a house)
  • Pets (one or more that belong to a person...no relation to house)
  • Toys (one ore more that belong to a pet...no relation to house or person)

I would like to return a dto with all the people, pets, and toys at a specific house. Household table has:

public virtual ICollection<Person> People { get; set; }

Person table has:

public virtual ICollection<Pet> Pets { get; set; }

Pet table has:

public virtual ICollection<Toy> Toys { get; set; }

GetHouseDataDto (the dto I am trying to return) has:

public HouseViewDto House { get; set; }
public ICollection<PersonViewDto> People { get; set; }
public ICollection<PetViewDto> Pets { get; set; }
public ICollection<ToyViewDto> Toys { get; set; }

I have the following query:

var house = await _houseRepository
    .GetAll()
    .Include(c => c.People)
    .FirstOrDefaultAsync(f => f.Id == input.Id.Value);
output.House = ObjectMapper.Map<HouseViewDto>(house);
output.People = ObjectMapper.Map< List<PersonViewDto>>(house.People);

How do I also include pets and toys?

Thanks.

Showing 21 to 23 of 23 entries