public string GetCatNameById(int id) { var q = (from r in edm.Categories where r.CategoryID == id select r); Category c = new Category(); c = q.First<Category>(); string name = c.Category_Name; return name; }
public int GetCatIdByName(string name) { var q = (from r in edm.Categories where r.Category_Name == name select r); Category c = new Category(); c = q.First<Category>(); int cid = c.CategoryID; return cid; }
public int AddNewCategory(string cat_name) { Category category_info = edm.Categories.FirstOrDefault(m => m.Category_Name == cat_name); Category category = new Category(); //int cat_ID; if (category_info != null) { category.CategoryID = category_info.CategoryID; } else if (category_info == null) { //Category category = new Category(); category.Category_Name = cat_name; edm.AddToCategories(category); edm.SaveChanges(); //cat_ID = category.CategoryID; } //cat_ID = category_info.CategoryID; return category.CategoryID; }
/// <summary> /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCategories(Category category) { base.AddObject("Categories", category); }
/// <summary> /// Create a new Category object. /// </summary> /// <param name="categoryID">Initial value of the CategoryID property.</param> /// <param name="category_Name">Initial value of the Category_Name property.</param> public static Category CreateCategory(global::System.Int32 categoryID, global::System.String category_Name) { Category category = new Category(); category.CategoryID = categoryID; category.Category_Name = category_Name; return category; }