views:

32

answers:

1

I have mapped the database in the edmx file from the database. Now how do I use linq to make a query?

here is an example of my problem

var Found = from o in ??????

What suppose to go in the question marks. How do I find what suppose to go in the question marks. I have tried many tutorials but that do not tell you exactly how to use Linq.

+5  A: 

Well, Entity Framework generates an ObjectContext for you. You should know the name of your ObjectContext class. Then to query using LINQ you can do something line that

using(var context = new NorthwindContext())
{
   var query = from p in context.ProductsSet select p;
   // then loop through your query instance.
}

The above example is very simple you should have a look at http://thedatafarm.com/blog/ for better tutorials

mosessaur
Hmmm..How do you find out the name of the ObjectContext?
@luke101: it's the name you defined in the entity model wizard (usually SomethingEntities)
Thomas Levesque