The type or namespace name 'MyDBEntities' could not be found (are you missing a using directive or an assembly reference?) RRS feed

  • Question

  • Hi i'm new to database, EF, linq etc.

    Went through similar questions and didn't find answer yet.

    1. i have a c# console program, builds and works fine.

    2. i added the LINQ to Entities data source to this project, the MyDB.mdf is created from MsSQL management studio.

       it succeeded, in the end VS 2012 ultimate displays "Modle1.edmx diagram".

    3. now in my main() i added 1 line,

        aded " using system.Data.Entities".

        MyDBEntities myDBEntities = new MyDBEntities();

        and build got the error type or namespace could not be found.

     Thanks very much !

    Friday, July 5, 2013 2:25 PM


  • Hi ningji;

    Please check to make sure that you are using the correct name for the context. If you look at the image below where the red outlined box is the name you should be using is located their. So if your shows Model1Container as the image shows then this line of code needs to change from this: 

    MyDBEntities myDBEntities = new MyDBEntities();

    To this:

    Model1Container myDBEntities = new Model1Container();

    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by ningji Sunday, July 7, 2013 12:20 PM
    Friday, July 5, 2013 6:28 PM