We are using EF5 and SQL Server 2012 the following two classes:
public class Question
{
public Question()
{
this.Answers = new List
Try these things:
Create()
method of DbSet
Answers
collection of your Context
You have set the QuestionId
appropriately for EF to realise the relationship. Also, do not explicitly set AnswerId to zero.
var a = new _uow.Answers.Create();
a.Text = "AAA";
a.QuestionId = 14;
_uow.Answers.Add(a);
var b = new _uow.Answers.Create();
b.Text = "BBB";
b.QuestionId = 14;
_uow.Answers.Add(a);
You may need to make a call to _uow.ChangeTracker.DetectChanges()
if you plan on querying the Answers
collection of Question
14