I am trying to add items to Item below but I get the following error;
Cannot implicitly convert the item to System.Collection.Generic.List
My Item type is as follows;
public class Item
{
[JsonProperty("variantId")]
public int variantId { get; set; }
[JsonProperty("quantity")]
public int quantity { get; set; }
[JsonProperty("returnReason")]
public ReturnReason returnReason { get; set; } = new ReturnReason();
}
public class RootObject
{
[JsonProperty("dropOff")]
public DropOff dropOff { get; set; } = new DropOff();
[JsonProperty("providerId")]
public int providerId { get; set; }
[JsonProperty("Reference")]
public string Reference { get; set; }
[JsonProperty("Id")]
public int Id { get; set; }
[JsonProperty("items")]
public List<Item> items { get; set; } = new List<Item>();
}
I understand that they are two different types but how would I overcome this
This is throwing the error;
items = (new Item
{
quantity = csv.GetField<int>(""),
variantId = csv.GetField<int>(""),
returnReason = new ReturnReason
{
code= csv.GetField<int>("")
}
})
Just to add more context this is how i am calling it
while (csv.Read())
{
var booking = new ReturnsBooking.RootObject
{
dropOff = new DropOff {dropOffPointId = csv.GetField<string>("DropOffPointId") },
providerId = csv.GetField<int>("ProviderID"),
orderReference = csv.GetField("OrderReference"),
returnMethodId = csv.GetField<int>("returnMethodId"),
items = new Item
{
quantity = csv.GetField<int>(""),
variantId = csv.GetField<int>(""),
returnReason = new ReturnReason
{
code = csv.GetField<int>("")
}
})
};
recordss.Add(booking);
}
return recordss;
when i try items.add i get an error stating items does not exist. I have also tried initialising Item..this doesn't seem to work either