Home > DeveloperSection > Forums > IList<string> datatype field not being incorporated into table definition asp.net MVC
Jeet Verma
Jeet Verma

Total Post:110

Posted on    December-23-2013 2:35 AM

 ASP.Net ASP.Net 

 1 Reply(s)
 1260  View(s)
Rate this:

I have the following model class:-

public class EventReg



    public int ID { get; set; }

    [Display(Name = "Event Date")]


    [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]

    public DateTime? EventDate { get; set; }

    [Display(Name = "Event Time")]


    [DisplayFormat(DataFormatString = "{0:t}", ApplyFormatInEditMode = true)]

    public DateTime? EventTime { get; set; }

    public IList<string> HashTags { get; set; }

    public string Category { get; set; }

    [Display(Name = "Registered by")]

    public string UniqueId { get; set; }

    public float Latitude { get; set; }

    public float Longitude { get; set; }

    public string Description { get; set; }            


In my Package-Manager-Console I typed Enable-Migrations -ContextTypeName CampusConnect.Models.EventDBContext(EventDBContext is my database ) to create a configuration.cs file.

 I didn't add any data into the seed method. then I did add-migration initial to create an intial.cs file which would allow my project to update my database schema. Now when I did update-database each field appeared in the table definition except the HashTag field. 

Can anyone tell me, why?

Pravesh Singh

Total Post:411

Posted on    December-23-2013 5:03 AM

Hi Jeet,

Because of HashTags property if of type IList - entity framework can't figure out how to declare it in database. So you need to help it. Basically you have two choices:

a) Make your field of string type and form it in your format (for example comma-separated string), then make additional property that will convert it to IList<string>:

public string HashTags { get; set; }

public string IList<string> HashTagsFormated


    get {

       return { HashTags.Split(',').ToList();



b) Make separate table for hash tags and link it to your EventReg table.

public class EventReg


   public EventReg()


       HashTags = new HashSet<HashTag>();


   //...your other fields

   public virtual ICollection<HashTag> HashTags { get; set; }


public class HashTag




    public int HashTagID {get;set;}

    public string HashTagName {get;set;}

    public virtual EventReg EventReg { get; set; }


Don't want to miss updates? Please click the below button!

Follow MindStick