none
Editing the .edmx file causes my objectcontext to stop working RRS feed

  • Question

  • Hi

    I'm having trouble when I edit my .edmx file in my C# desktop app. I'm currently trying to teach myself to make a Windows Forms app in Windows 8.1.

    I'm not sure if objectcontext is the right word but that's what I got from a tutorial. Anyway, things were working file until after I updated my .edmx file after I made changes to my SQLServer 2014 Express database (I added a column to one of the tables). I'm using Visual Studio 2013 Express. I've got the following code:

    using System;

    using System.Collections.Generic;

    using System.Collections;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using System.Windows.Forms;

    using System.IO;

    using System.Data.SqlClient;

    using System.ComponentModel;

    using System.Data.Entity;

    using System.Data.Entity.Validation;

    using System.Data.Linq;

    using System.Configuration;

    using System.Data;

    // Create objectcontext object

           myAppEntities db = new myAppEntities();

    The above "myAppEntities db = new myAppEntities();" line stops working after I update the .edmx file. I get a red line under the second myAppentities(). I'm getting the name myAppEntities from the name of the connection string in app.config I've got 3 other connection strings still in app.config as a result of my still learning how to program in C#.

    I tried updating the .edmx file by right clicking on it and then clicking on "Update model from database...". That's what caused my problem, i.e. when the second myAppEntities(); in that line got the red line under it.

    I've restored my project from a backup so the red line is gone now. I just need to know how to update my .edmx file in a way that it doesn't upset my objectcontext creation. Should I just delete the .edmx file and start from scratch? Or is there something else I am doing wrong?

    I did find this link on stackoverflow but I'm not confident about trying what's said there:

    http://stackoverflow.com/questions/690248/updating-your-edmx-to-reflect-changes-made-in-your-db-net-linq-to-entities

    Thanks.






    • Edited by thisman Tuesday, June 17, 2014 5:46 PM
    Tuesday, June 17, 2014 5:44 PM

Answers

  • Just delete the edmx and start over...

    And use source control!


    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    • Marked as answer by thisman Wednesday, June 18, 2014 6:10 AM
    Tuesday, June 17, 2014 6:14 PM

All replies

  • Just delete the edmx and start over...

    And use source control!


    Please mark as answer, if this was it. Visit my SQL Server Compact blog http://erikej.blogspot.com

    • Marked as answer by thisman Wednesday, June 18, 2014 6:10 AM
    Tuesday, June 17, 2014 6:14 PM
  • Thanks ErikEJ. That solved my problem.

    I've been looking up tutorials on source control. Thanks for your suggestion.

    Wednesday, June 18, 2014 6:12 AM