Search code examples
c#asp.net-mvcasp.net-core

How do I make a column in SQL that's an array of data in .NET Core MVC?


I have my models page, but one thing I can't seem to do is get a property to be a List/Array.

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace MVCPractuce.Models
{
    public class Stoof
    {
        public int StoreID { get; set; }
        public string StoreName { get; set; }
        public int StoreYear { get; set; }
        public decimal StoreCost { get; set; }
        public string StoreMotto { get; set; }
        public int StoreLikes { get; set; }
        public List<string> StoreItems { get; set; }

        public Stoof()
        {

        }

    }
}

I get the error of could not be mapped because it is of type List which is not supported primitive type. Anyone know how I can fix this?


Solution

  • public ICollection StoreItems { get; set; }

    ICollection needs to be type of StoreItems. Then add foreign key ref into StoreItems entity for proper mapping