问题描述:

I am having a Azure Mobile Service and its running fine except i have problems with AutoMapper and DTO's with other DTO's inside of them. Basically they are ignored in the output.

My Data class:

public class FoodSupplyProvider

{

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]

[Index(IsClustered = true)]

[Key]

public int FoodSupplyProviderId { get; set; }

public string Name { get; set; }

public virtual Branche Branche { get; set; }

}

public class Branche

{

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]

[Index(IsClustered = true)]

[Key]

public int BrancheId { get; set; }

public string BrancheName { get; set; }

}

My DTO classes

public class BrancheDTO : EntityData

{

public string BrancheName { get; set; }

}

public class FoodSupplyProviderDTO : EntityData

{

public string Name { get; set; }

public BrancheDTO Branche { get; set; }

}

I have registered the mappings with the Mapper:

cfg.CreateMap<Branche, BrancheDTO>();

cfg.CreateMap<FoodSupplyProvider, FoodSupplyProviderDTO>();

Output:

When i try to output the FoodSupplyProviderDTO, it is as follows:

[{

"id":"2b3fdde5-ba55-4e7f-ae74-5e23abaa7b64",

"name":"FoodSupplyProvider Name 1"

}]

I would expect it to be:

[{

"id":"2b3fdde5-ba55-4e7f-ae74-5e23abaa7b64",

"name":"FoodSupplyProvider Name 1"

"branche":"The BrancheDTO goes here...."

}]

Please note, the expected output is also what the documentation says on my API.

I have checked that the value is not null, i have even tried mapping the Name of the Branche to the Name of the FoodSupplyProviderDTO and that works perfectly fine, except that the Branche is still not present in the output.

EDIT:

As @YacoubMassad said, it could be the mapping or the serilization fail. I have tried outputting the mapping and it works as intended. I then tried to json serialize it in code and output the result. That one is as the expected result shown above.

So the problem lies with the WebApi serialising the object for me. Is there anyway i can debug this?

相关阅读:
Top