How to refer entity object in code behind

Posted on 2011-10-13
Last Modified: 2012-06-27

I am very new in using ADO.Net 4.0 entity model. i have configured the same for MySQL using the below link
Now i am just clueless what to do next, how to refer the object to query the database.

Please help
Question by:ExpertHelp79
    LVL 17

    Expert Comment

    You need to create object of MySqlEntities (this name is context name when you add model to your project). For instance
    var context = new MySqlEntities();
    Then you call refer the entity object.
    e.g. if you want all persons then
    var allPersons = from p in context.Persons select p;
    LVL 2

    Author Comment

    i tried but i am not able to create
    GA.edmx this i have created in the app_code section.

     <add name="GrabAdventureEntity" connectionString="metadata=res://*/App_Code.GA.csdl|res://*/App_Code.GA.ssdl|res://*/App_Code.GA.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;User Id=root;Persist Security Info=True;database=grabadventure&quot;" providerName="System.Data.EntityClient" />

    this is in the web config

    now when i am typing  GrabAdventureEntity it is not detecting
    LVL 8

    Expert Comment

    Can you check name of the Context class? You can check it in the Designer.cs file of the model. Expand the edmx node below it you will find this file.

    Are you including the namespace in which your Model is defined? Again you can see the namespace in the same designer.cs file.
    LVL 2

    Author Comment

    Name Space for default.aspx : namespace GrabAdventure
    Name space for GA. Designer.cs: namespace GrabAdventure.App_Code

    how will i refer the same in default.aspx
    LVL 8

    Accepted Solution

    In the Default.aspx.cs alongside other using statements put,

    using GrabAdventure.App_Code;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now