Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Entity Framework 101
Message
De
03/06/2014 11:41:19
 
 
À
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:
01601206
Vues:
42
>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.

Your context is what controls access to the database. It tracks the changes in your entities, the connection to the database, and keeps a local cache of retrieved entities. The Products property of OrdersContext is called because db is an instance of OrdersContext in that controller.

If you want to see what is actually being executed, the easiest way is to enable logging if you are using Entity Framework 6. See http://msdn.microsoft.com/en-us/library/dn469464.aspx. You can also check the ToString method for an IQueryable variable, or try casting it to an ObjectQuery and check its ToTraceString method.

For using Entity Framework with an existing database, look into reverse engineering code first. Instructions can be found here: http://msdn.microsoft.com/en-us/data/jj200620.aspx.

For using stored procedures, look at http://msdn.microsoft.com/en-us/library/dn468673.aspx or if you are using Database first or Model first for an older version of Entity Framework, see http://msdn.microsoft.com/en-us/data/gg699321.aspx.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform