I was hoping someone else would jump on this who is an expert, but one issue I see you're going to have is that your instance of OfflineEntry
is not created from your DbContext, and thus LazyLoading isn't going to work.
Generally it is better practice to not use your entity models as your view models, this being one of the reasons.
So my suggestion would be to create an NewOfflineEntryViewModel
like below:
public class NewOfflineEntryViewModel
{
public int CategoryId { get; set; }
}
and then retrieve the Category from the DbContext manually
public ContentResult Save(NewOfflineEntryViewModel model)
{
var category = db.Categories.Find(model.CategoryId);
var newEntry = db.OfflineEntries.Create();
db.OfflineEntries.Add(newEntry);
newEntry.Category = category;
db.SaveChanges();
var categoryName = category.Name; //for whatever you needed with this
return Content("ok");
}