.net framework, asp.net 4.0, asp.net tutorials, asp.net, c#, Code generation, Enitities, entity, Entity Framework, entity framework profiler

EF takes the expression and parses that into corresponding SQL. It’s not that the linq query directly is sql itself.Entity framework also supports adding views from our database and apoun adding and saving the same, code is automatically generated which allows us to fetch data from our view.Now consider the following example:

var result = from b in ctx.View_Inventory_Total select b;

Now here I am assuming that entity framework has generated a class corresponding to my view named as  View_Inventory_Total. In order to make things clear just put a breakpoint after you just fetch the data from the result object using foreach loop.

And then switch over to the entity framework profiler.

Now you would be able to view what query is hitting against Database for that view. This would not had been possible in normal cases where programmer never is aware of what query a view is executing.

Now we come on to the stored procedures. Consider we have a stored procedure named CustomerSales and we try fetching data directly from it in our code, but we will find out that SP does not exist because entity framework needs typed data in order to convert them to classes. So right click on the stored procedure through server explorer and click “Add function import” and select your stored procedure from the dialogue box. And now you have to specify the return type of the SP. Assuming that you don’t have any information on it you can select ‘Complex Type’ and Just create an entity for yourself by clicking on Ok.

Now if you go to your code and try rewriting the query you would be able to find out a new method which has been generated by entity framework that corresponds to your SP.

 

Returned by this query will be a complex type of which attributes would be known at compile time.

 

How convenient!