I am trying to define an EF Model containing a list or array of <string>. Using Add-Migration/Update-Database the field does not get added to the database table.
What I want is a field that would contain a comma-separated list of string values. There may be only a single value, or there could be 10 or more:
"Value1, Value2, ..."
I'd like to be able to use this field within my MVC5/EF6 web application as a key. For example:
IEnumerable<Param> params =
from u in _context.Params
where u.MyValues.Contains("Value1")
select u;
I know this code is wrong, but here is what I am attempting:
public class Param
{
public int Id { get; set; }
public string[] MyValues { get; set; }
}
My DbSet:
public DbSet<Param> Params { get; set; }
The MyValues field doesn't get added to the schema and there are no errors thrown. Here is the Seed():
context.Params.Add(c => c.Id, new Param { MyValues = new[] { "Value1, Value2" } });
How can I add a field that contains a comma-separated list of string values that can then be accessed/queryied?
IList<string> MyValues, but apparently EF6 will not create a database field of this type. I triedstring[]as you can see, but that didn't generate a field either. I think Pragmateek provided some hints of how I can use a string to make it work.