Click here to Skip to main content
15,176,561 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to query an entity that is mapped to the corresponding database table to retrieve some data?

I have a User entity which OR mapped to the database table User, which attributes userID and username.

Now, I wanted to know what are the possible ways to retrieve the the UserName by providing the userID.

I tried using the following code , but I dont understand why is it displaying an error that the datacontext does not exist.

SQL
var CurrentUserName = from c in datacontext.user
                      where c.UserID == someUserID
                      select c.Name;
Posted

You need to define the datacontext before using it:

C#
datacontext = new MyEntities();


MyEntities is created when you add an "ADO.NET Entity Data Model" to your project (you can name it whatever you want).
   
Try entity framework tutorial on below link. Very nice
http://www.entityframeworktutorial.net[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900