I want to create a Blog object which has a relation between User. To create the relationship do I have to select User entity first, then set it to User property of Blog object? In Entity Framework samples suggest to set the User object to ViewState and retrieve it when you need to create the relationship, like a basic cache.
Is this necessary? Is there any other way to do this? (like in linq-to-sql setting the foreign keys only without select.)
Here my code sample;
Blog blog = new Blog
{
Name = blogName,
Slogan = slogan,
User = Entities.Users.First(u => u.Id == userId)
}
Entities.AddToBlogs(blog);
Entities.SaveChanges();
Edit(To give another chance to question): Is there anything unclear or else?