parent, child

May 15, 2013 at 2:30 PM
I am extremely new to both entity framework and EntitiesToDTOs.
Making up a generic example assuming clients have lots of email addresses.

public List<ClientsDTO> GetClients()
{
using (myEntities = new myEntities ())
{
var q = (from c in ctx.Clients.Include("EmailAddresses")
select c
).ToList();

return q.ToDTOs();

}

So viewing q in the debugger it seems to work fine returning list of Clients and Email Addresses. However when its transferred across a service it seems to only transfer the Clients and not the children email addresses. I think its down to the EmailAddresses being an entitycollection and not a dto collection, but I cant see a way of changing this in the automatic code generation. Hope this makes sense
Coordinator
Jun 28, 2013 at 1:11 AM
Hi @neilbhatia
Sorry for the too late response, been busy with other projects.
Could you share the code generated by the tool? The DTOs code for Client and EmailAddress.
Thanks!
Jun 28, 2013 at 8:34 AM
Hi

thanks for the response, I think I have figured it out, something like...

public ClientsDTO GetClients()
{
using (myEntities = new myEntities ())
{
var q = (from c in ctx.Clients.Include("EmailAddresses")
select c
).SingleOrDefault();
 ClientsDTO clientdto = q.ToDTO();
foreach(var emailaddresses in q.EmailAddresses)
{
      EmailAddressesDTO emailaddressesdto =  emailaddresses .ToDTO();
      clientdto.EmailAddresses.Add(emailaddressesdto );

}
return clientdto();

}

Loving the kit btw.
Marked as answer by ffernandez on 12/30/2013 at 6:52 PM
Coordinator
Jul 10, 2013 at 4:19 AM
Great!
Thanks for using the tool!