public void Save(ProductCategoryItem item) { var errors = item.GetValidationErrors(); errors.ThrowIfHasErrors(); var category = item.Id == 0 ? Db.CreateAndAdd <tblProductCategory>() : Db.Set <tblProductCategory>().Single(x => x.Id == item.Id); category.Name = item.Name; category.ParentCategoryId = item.ParentCategoryId; Db.SaveChanges(); item.Id = category.Id; }