Sugestion on a better way to code this EF update? I have a block of code that pulls the current menu position and compares it to what users selected, if the selection is different the database is updated with the new selection. As I am still new with EF I was hoping for a general code review for suggestions on a possible better, more efficient, and/or easier way to code this. Here is my existing code:

using (var db = new SectionInfoAdmin())
{
    var dtCategories = (from n in db.Navigation
    where n.SectionID == SectionID
    select new
    {
       n.Category
    }).ToList();

 string PrimaryCategory = dtCategories[0].Category.ToString();

 if (ddlPrimaryCategory.SelectedValue != PrimaryCategory)
 {
    var Category = (from n in db.Navigation
    where n.Category == PrimaryCategory &amp;&amp; n.SectionID == SectionID
       select n).First();

    Category.Category = PrimaryCategory;
 }

 if (dtCategories.Count &gt; 1)
 {
    string SecondaryCategory = dtCategories[1].Category.ToString();
    if (ddlSecondaryCategory.SelectedValue == SecondaryCategory)
    {
       var Category = (from n in db.Navigation
       where n.Category == SecondaryCategory &amp;&amp; n.SectionID == SectionID
          select n).First();
       Category.Category = SecondaryCategory;
    }
 }
 db.SaveChanges();
 lblResults.Text = "Information updated.";
}
As @dreza mentioned, you might want to move the code around your LINQ-Statements to a method.

public void changeCategoryTo(String newCategory){
   var record = (from n in db.Navigation where n.Category == newCategory
                   &amp;&amp; n.SectionId == SectionID select n).First();
   record.Category = newCategory;
}


this greatly reduces duplication. 

further points:


Try to stick to either camelCase or MixedCase to have consistent and speaking variable names:


something like var Category, String PrimaryCategory and similar are diffifult to associate to clear roles in your code.
try to refrain from naming your variables after their type only, this leads to greatly increased effort when handling multiple objects of the same type.

Your if-statement for updating the SecondaryCategory is different from the if-statement for updating PrimaryCategory