0

I have two entities. Groups. Pools. A Group can create many pools.

So I setup my Pool table to have a GroupID foreign key.

My code:

using (entity _db = new entity()) {
    Pool p     = new Pool();
    p.Name     = "test";
    p.Group.ID = "5";
    _db.AddToPool(p);
}

This doesn't work. I get a null reference exception on p.Group.

How do I go about creating a new "Pool" and associating a GroupID?

0

1 Answer 1

1

You can either load the existing Group object, say group, from your context and then set p.Group = group or with EF4 you can set the GroupID on your pool directly since it can expose the foreign key properties if you specify that in the EDMX.

Sign up to request clarification or add additional context in comments.

1 Comment

I ended up just using p.Group = group;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.