I have the following code-first model:
public class TestContext : DbContext
{
public TestContext() : base("Data Source=Test.db") { }
public DbSet<Item> Items { get { return this.Set<Item>(); } }
}
public class Item
{
public Int32 Id { get; set; }
public virtual ICollection<SubItem1> SubItems1 { get; set; }
public virtual ICollection<SubItem2> SubItems2 { get; set; }
}
public class SubItem1
{
public Int32 Id { get; set; }
public Int32 ItemId { get; set; }
public Item Item { get; set; }
public String Test { get; set; }
}
public class SubItem2
{
public Int32 Id { get; set; }
public Int32 ItemId { get; set; }
public Item Item { get; set; }
public Int32 TestCode { get; set; }
}
When used like this:
using (var context = new TestContext())
{
context.Items.Add(new Item());
context.SaveChanges();
}
I get an an exception which says "Default values not supported". This exception is thrown from DmlSqlGenerator.GenerateInsertSql and propagated up.
Originally I got the exception with much more complex schema, but I was able to boil it down to this. Is this a limitation of SQL CE? How can I get around it and have a principal item with two sets of dependent items each of which have scalar values?