Base solution for your next web application

Activities of "klawsuc"

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.

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?

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.

I'm having a similar issue using build 4.1.1 (Core1.1 + Angular4). My projects are merged. I can build the project and run it in development but when I publish the Host project I get this error:

Can't resolve './$$_gendir/root.module.ngfactory' in 'C:\inetpub\aspnetzero_angular_4.1.1\aspnet-core\src\MyPorject.Web.Host\src' MyProject.Web.Host

I followed this documentation: <a class="postlink" href="https://www.aspnetzero.com/Documents/Merge-Angular-Client-Server">https://www.aspnetzero.com/Documents/Me ... ent-Server</a>

Using build 4.4.0 (Core + Angular), Visual Studio 2017, Typescript 2.5 (installed VS extension). I get the following error when I try to build the *.Web.Host project.

npm - v5.4.1 node - v6.11.3 tsc - v0.8.3.1

I also have a solution built on 4.1.1 and it works fine. The one thing I did for the 4.4.0 build is to add the nuget package System.ComponentModel.TypeConverter to all the projects as proposed at #3739@78245cf2-355c-4cd1-a9a8-be05b24814ae

I turned on detailed logging and here is where the issue occurs:

C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.exe --project "C:\inetpub\myproject_4.4.0\src\MyProject.Web.Host\e2e\tsconfig.json" --listEmittedFiles --locale en-US
Unknown output: Unknown extension for file: "C:\inetpub\myproject_4.4.0\src\MyProject.Web.Host\e2e\tsconfig.json". Only .ts and .d.ts extensions are allowed.
Unknown output: Unknown extension for file: "en-US". Only .ts and .d.ts extensions are allowed.
Unknown output: Unknown option 'project'
Unknown output: Use the '--help' flag to see options
Unknown output: Unknown option 'listEmittedFiles'
Unknown output: Use the '--help' flag to see options
Unknown output: Unknown option 'locale'
Unknown output: Use the '--help' flag to see options
C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.5\build\Microsoft.TypeScript.targets(247,5): error MSB6006: "tsc.exe" exited with code 1.

Digging a bit further, looks like Target CompileTypeScriptWithTSConfig: Task "VsTsc" are running C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.exe which is an old VS 2012 file. How do I force it to use C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.5\tsc.exe?

I already have the following in the csproj file:

<TypeScriptToolsVersion>2.5</TypeScriptToolsVersion>

Seems like I'm just talking to myself here but in case someone comes across this and has an answer. I added the following to csproj but I not sure what the side effects might be:

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

Here is the log related to the tsc where I had an issue previously

Target PreComputeCompileTypeScriptWithTSConfig:
Using "VsTsc" task from assembly "C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.5\build\TypeScript.Tasks.dll".
Task "VsTsc"
    Unknown output: TypeScript compile is skipped because the TypeScriptCompileBlocked property is set to 'true'.
Done executing task "VsTsc".
Task "VsTsc"
    Unknown output: TypeScript compile is skipped because the TypeScriptCompileBlocked property is set to 'true'.
Done executing task "VsTsc".
Target CompileTypeScriptWithTSConfig:
  Task "VsTsc"
    Unknown output: TypeScript compile is skipped because the TypeScriptCompileBlocked property is set to 'true'.
Done executing task "VsTsc".
  Task "VsTsc"
    Unknown output: TypeScript compile is skipped because the TypeScriptCompileBlocked property is set to 'true'.
 Done executing task "VsTsc".

Still having an issue trying to get the site published properly. One thing I noticed is that tsc.exe is being called at C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.exe. That version is for VS 2012 (which I still have installed for legacy apps). However I have TS 2.1, 2.3, and 2.5 installed in their respective directories. In the project file I specify the target TS to be 2.5 (<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>). So the error happens at

C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.5\build\Microsoft.TypeScript.targets(247,5): error MSB6006: "tsc.exe" exited with code 1.

But the initial tsc file that's called is

C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.exe --project "C:\inetpub\SquireLab_angular_4.1.1\aspnet-core\src\SquireLab.Web.Host\e2e\tsconfig.json" --listEmittedFiles --locale en-US

Is it normal for two different tsc programs to be called? Is there a way to only use 2.5?

Showing 1 to 10 of 23 entries