I am trying to jump from ASP Classic to asp.net. I have followed tutorials to get Entity Framework and LINQ to connect to my test database, but I am having difficulties figuring out ExecuteQuery(). I believe the problem is that I need an “entity class” for my database, but I can’t figure out how to do it. Here is my simple code:
Dim db as New TestModel.TestEntity
Dim results AS IEnumerable(OF ???) = db.ExecuteQuery(Of ???)("Select * from Table1")
From the microsoft example site, they use an entity class called Customers, but I don’t understand what that means.
Entity Framework comes with a visual designer. In that designer, you connect to your existing database, and you select all the tables (and possibly views) from your database that you want to work with.
From that selection, EF will generate entity classes one for each of your tables, e.g. if you have a
Customerstable, you’ll get aCustomerclass, if you have aProductstable, you get aProductclass.Those classes represent (by default) your table structure 1:1 – e.g. each column in your table gets translated into a property on the class.
Once you have that, you’re no longer dealing with SQL statements and stuff like
ExecuteQuery()– you leave that to EF to handle for you.You just ask for what you need, e.g. all your customers from a given state:
This statement will return an
IEnumerable<Customer>– a list of customers that matches your search criteria.