C#C
C#3y ago
_vegabyte_

❔ Saving a JSON object to Database

HI. I want to save a Array to Database but I'm this error.

"Error getting value from 'Values' on 'ELIXIR.DATA.DATA_ACCESS_LAYER.MODELS.QC_CHECKLIST.CheckListString'.",

 public class CheckListString
    {
        [Key]
        public int ChecklistStringId { get; set; }
        public int? PO_Summary_Id { get; set; }
        public int? ReceivingId { get; set; }
        public string Checlist_Type { get; set; }

        [NotMapped]
        public List<string> Values
        {
            get => JsonSerializer.Deserialize<List<string>>(Value);
            set => Value = JsonSerializer.Serialize(value);
        }
        public string Value { get; set; }

        public string Remarks { get; set; }
    }

public async Task<bool> AddChecklists(Checklists input)
        {
            foreach (var checklistString in input.ChecklistsString)
            {
                var newChecklistString = new CheckListString
                {
                    PO_Summary_Id = checklistString.PO_Summary_Id,
                    Checlist_Type = checklistString.Checlist_Type,
                    Values = checklistString.Values,
                    Remarks = checklistString.Remarks
                };
                await _context.CheckListStrings.AddAsync(newChecklistString);
            }

            await _context.SaveChangesAsync();

            return true;
        }


This is the body
{
  "checklistsString": [
    {
      "checklistStringId": 0,
      "pO_Summary_Id": 0,
      "receivingId": 0,
      "checlist_Type": "string",
      "values": [
        "string"
      ],
      "value": "string",
      "remarks": "string"
    }
  ]
}

Any help will be much appreciated
Was this page helpful?