The problem with the accepted answer is that any changes to the contents of the list (adding, changing or deleting entries) will not be tracked using EF.
Here is my solution inspired by this great blog post .
This class performs serialization and deserialization, so the collection can be stored in one column of the parent model:
[ComplexType] public class DateTimeCollection : Collection<DateTime> { public void AddRange(IEnumerable<DateTime> collection) { foreach (var item in collection) { Add(item); } } [Column("Times")] public string Serialized { get { return JsonConvert.SerializeObject(this); } private set { if (string.IsNullOrEmpty(value)) { Clear(); return; } var items = JsonConvert.DeserializeObject<DateTime[]>(value); Clear(); AddRange(items); } } }
What is it! Now you can use this new collection in your parent class exactly as you expected. Changes to the contents of the collection will be tracked.
public class Company{
source share