public void Save(Activity activity) { activityContext.Activities.Add(activity); activityContext.Attach(activity.Category); if (activity.Subcategory != null) { activityContext.Attach(activity.Subcategory); } activityContext.SaveChanges(); }