Reputation: 3914
I'm using AutoMapper to map from one type to it's Dynamo equivalent. I want to store a list ob objects within the Dyanmo object so I'm converting it's child objects to Dynamo Documents. However, when I try to update Dynamo with the new type, it's giving me this error:
Type Amazon.DynamoDBv2.DocumentModel.DynamoDBEntry is unsupported, it cannot be instantiated
Here is my model:
public class TourDetail
{
[DynamoDBHashKey]
public string TourId { get; set; }
public DynamoDBList Itinerary { get; set; }
}
Here is my AutoMapper code:
public DynamoModelMapper()
{
CreateMap<TourDetail, Models.Dynamo.TourDetail>()
.ForMember(x => x.Itinerary, x => x.MapFrom(y => convertItinerary(y.Itinerary)));
}
private List<Document> convertItinerary(IEnumerable<TourItineraryDay> itineraryDays)
{
var docList = new List<Document>();
foreach (var itineraryDay in itineraryDays)
{
var doc = new Document();
doc.Add("day", itineraryDay.Day);
doc.Add("title", itineraryDay.Title);
doc.Add("description", itineraryDay.Description);
docList.Add(doc);
}
return docList;
}
Upvotes: 0
Views: 1566
Reputation: 3914
The issue was that I am mixing the Dynamo Data Model and the Document Model in my example. When using the Data Model, you do not need to worry about converting your collections to Dynamo-specific types like DynamoDBList
or List<Document>
. These types are part of the Document model and are not necessary with the Data Model.
The solution was to just change the Itinerary
property in my TourDetail
model to type List<TourItineraryDay>
and removed the explicit Automapper mapping for that member.
public class TourDetail
{
[DynamoDBHashKey]
public string TourId { get; set; }
public List<TourItineraryDay> Itinerary { get; set; }
}
Upvotes: 1