Using ComplexType with ToList causes InvalidOperationException
- by Chris Paynter
I have this model
namespace ProjectTimer.Models
{
    public class TimerContext : DbContext
    {
        public TimerContext()
            : base("DefaultConnection")
        {
        }
        public DbSet<Project> Projects { get; set; }
        public DbSet<ProjectTimeSpan> TimeSpans { get; set; }
    }
    public class DomainBase
    {
        [Key]
        public int Id { get; set; }
    }
    public class Project : DomainBase
    {
        public UserProfile User { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public IList<ProjectTimeSpan> TimeSpans { get; set; }
    }
    [ComplexType]
    public class ProjectTimeSpan
    {
        public DateTime TimeStart { get; set; }
        public DateTime TimeEnd { get; set; }
        public bool Active { get; set; }
    }
}
When I try to use this action I get the exception The type 'ProjectTimer.Models.ProjectTimeSpan' has already been configured as an entity type. It cannot be reconfigured as a complex type.
public ActionResult Index()
        {
            using (var db = new TimerContext())
            {
                return View(db.Projects.ToList);
            }
        }
The view is using the model @model IList<ProjectTimer.Models.Project>
Can any one shine some light as to why this would be happening?