views:

110

answers:

2

I am getting this error when I try to do an insert on a column that is a foreign key. Here is how I am assigning the value

var at = MvcApplication1.Entity.alttitles.Createalttitles(0, altTitleText);
        at.question.question_id = questionid;   //Error here
        at.userinfo.user_userid = _AuthorID;    //Error here
        context.AddToalttitles(at);
        res = context.SaveChanges();

When I made the question_id and the userid a foreign key I started getting this error. Is there a way to fix this?

A: 

Check if at is not null before assigning its properties?

Gregoire
+1  A: 
marc_s
Your examples are backwards. "Reference" is for 1:1.
Craig Stuntz
oops - thanks for pointing that out! Haven't been using it much lately (waiting for EF4), so my memory begins to slip :-)
marc_s
Createalttitles is a entity sql create function to insert new rows in the database. It does not have an Include option in intelisense
ah okay, I didn't know if it was returning a IQueryable<T> interface or not; in that case, do any of the other ideas help? I am almost certain this is the root cause of the problem - the "question" property is not being populated automatically (since EF does not do that)
marc_s
OK..No problem..I will try this as soon as I get home..thank you