public void SaveCategory(Category category)
{
if (category.CategoryId == 0)
{
context.AddToCategories(category);
}
else
{
try
{
context.UpdateDetachedEntity<Category>(category, x => x.CategoryId);
}
catch (Exception)
{
context.ApplyCurrentValues<Category>(category.EntityKey.EntitySetName, category);
}
}
context.SaveChanges();
}