Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Entity Framework 101
Message
De
03/06/2014 12:33:10
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
03/06/2014 08:58:14
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Versions des environnements
Environment:
C# 4.0
OS:
Windows 8
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01601183
Message ID:
01601210
Vues:
37
db.Products.AsEnumerable();
The query executes when you actually enumerate the results, so in that instance AsEnumerable() actually kicks off the query. See LINQ's Deferred Execution feature for more reference. It also makes it possible to do something like this:
   var query = db.Products.AsQueryable(); //this does not execute the query

   if (productNameFilter != null
   {
      query = query.Where(p => p.ProductName == productNameFilter); //Still does not execute...
   }

   return query.ToArray(); //The ToArray() kicks off the execution, because it takes it out of IQueryable data type.
>Hi,
>
>I am following this online example:
>
>http://www.asp.net/web-api/overview/creating-web-apis/using-web-api-with-entity-framework/using-web-api-with-entity-framework,-part-3
>
>and need some clarification on how the data is actually getting pulled from the database.
>
>Can someone explain to me what happens when a request is sent to http://localhost:portnum/api/admin
>
>I think the call gets routed to
>
>
        // GET api/Admin
>        public IEnumerable<Product> GetProducts()
>        {
>            return db.Products.AsEnumerable();
>        }
>
>in the AdminController.cs
>
>And I gather that db.Products.AsEnumerable() is what actually queries the database and returns the data.
>
>Somehow the
DbSet<Product> Products { get; set; }
defined in OrdersContext.cs gets involved here too.
>
>My problem is that I am trying to adapt this to using an existing database of my own and can't work out how to tell it what data I want to be pulled back (I need it to call a Stored Procedure in my database).
>
>Any help appreciated.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform