Getting SQL queries generated with Entity Framework Plus? - entity-framework-6

I am enjoying the features of Entity Framework Plus over Entity Framework 6 since a few hours, and especially its IncludeFilter.
With regular Entity Framework 6, I was able to simply call ToString() on an IQueryable to easily get the SELECT query that will be actually processed on DB Server.
But with EF+, when I apply an IncludeFilter, I only get :
Z.EntityFramework.Plus.QueryIncludeFilterParentQueryable`1[MyRecord]
Because ToString() seems to not be overloaded the same way in EF+.
Is there a way to get SQL generated for "IncludeFilter" queries as well as for classical queries ?
I know I could get it on SQL server itself with the adequate profiling tools, but I would like to be able to do it on code side in EF.

Is there a way to get SQL generated for "IncludeFilter" queries as well as for classical queries ?
No, there is currently no way.
It might come later but at this moment, the library doesn't offer this feature.
(I'm the owner)
EDIT: Answer comment
My main worry was to know if the generated queries are optimized
I would not call them optimized. They are generated by Entity Framework and nothing is really modified on our side.
IncludeFilter: Create one VERY big query like Include does in EF6
IncludeOptimized: Create multiple small queries like Include does in EF Core

Maybe a little late but you could use SQL Server Profiler to trace database events (e.g., queries). Using SQL Tuning profile it will trace your queries and you can have a look at them in SQL.

You can use the current context's log to track all requests performed under this instance
context.Database.Log = s => Console.WriteLine(s);

Related

How to calculate number of database queries in a MVC project?

We calculate the no. of db queries in ASP.NET application by searching for ".fill(" or ".execute" and then looking for the query/stored proc.
What is the way we can find the no. of db queries in an MVC application?
This is as part of application analysis...
I don't know much about your application but I would try to do the following:
use SQL profiler to see which queries are executed
create a web crawler to get a list of all links in the application
click on each link (by hand or from the code) and analyze results from SQL Profiler
Search for "DbContext" in the entire solution.
This will take you to the controller.
Within the Method inheriting from dbcontext, you get name of all the DbSets.
Then you can search for each "DbSetName" which will lead you to the LINQ query!

Breeze Save - Error: CROSS APPLY is not supported by Oracle

I am saving a complex object graph from breeze, and I get the following error from the server:
Error: CROSS APPLY is not supported by Oracle
We are using an Oracle database using Devart provider. From my research, it seems that the only solution to this problem is to avoid certain linq query expressions. These threads provide further context:
http://forums.devart.com/viewtopic.php?t=18849
http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/ae826dd9-1bab-4f64-a7ee-f082a2177346/
The last thread linked is particularly disheartening, as this appears to be a Microsoft-related EF issue on which they have gone dark on for quite some time.
Since the only remedy for this appears to be avoiding specific linq operators/expressions, I must ask if there is any way to use breeze and avoid these offending linq expressions? If not, I am lead to conclude that breeze is currently limited only to relational databases that are fully-supported by EF, which from the my research is effectively only MS SQL.
Hoping I am wrong,
Mathias
If you want to use Breeze's EFContextProvider then you are limited to using an EF backend. However you do some other options. The first is that you can pass your own parameters into your controller methods, ( see the EntityQuery.withParameters method). This may allow you to rewrite your expression on the server to avoid EF expressions that cannot be tranlated properly for Oracle.
In addition, you can use Breeze with your own custom context provider or you can take over the server side completely. The first is a good approach if you are talking to another .NET backend, the second is appropriate when you are talking to an arbitrary non .NET backend.
We are planning on releasing an NHibernate backend to breeze as well as a Node-MongoDb backend within the next few weeks to illustrate both of these.

Using LINQ and ADO.NET Entity Data Model

Is it possible to use LINQ and ADO.NET Entity Data Model together in a project? I have a project built on ADO.NET Entity Data Model from a previous user and has .edmx file, but I am used to hard coding everything, opening connections via ADO.NET.
Is there problems using both together in an MVC project?
LINQ(Language Integrated Query) is TSQL in C# (yes we can query xml, lamda expression etc its lot more but mostly used for TSQL...) you can write LINQ queries against LINQ to SQL (.dbml) OR Entity Framework (.edmx) by creating the Context of each there is a bit of diff in calling methods like in EF Object.AddToObject(o) and in LINQ to SQL Object.InsertOnSubmit(o) and .Savechanges()/Submitchanges()
LINQ to SQL supports only MS SQL server but EF can support other databases as well i.e. MY SQL etc
and if you are using any of these in your project you can still use old Ado.net anywhere in your project by providing proper info to methods or call stored procedures by passing parameters after opening connection like we did in old days......
Linq is simply a way of writing your sql in C#. Well it's lot more than that really. But in this context whereever you would put some sql, you use linq intead so it's agnostic as far as EF is concerned. Or any other framework for that matter.
The real bonus is with a bit of thought you can use something other than a sql database for your persistence.
There are 2 sorts of Linq
Linq To Objects and Linq to SQL
Linq to SQL wont work on your ADO Model as that requires a Direct link to the SQL
but Linq to objects will work on the ADO models objects just as easily as any other
in real terms all this means is that instead of managing the construction for the query's in the DB Linq will let ADO handle it, you wouldn't see any difference

Is EntityFramework using linqtosql underneath?

I am quite new to entity frame work 4.0 and what I know from my intial analysis is entity framework is nothing but an abstraction of ado.net with its storage model, conceptual schema and the mappping between these two.But one thing I am unclear is while fetching data from database or executing any stored procedure what mechanism its following.
Is it adopting the traditional ado.net approach or is it the concept of linq2sql?
The reason I am asking this question is in our project we are not suppose to use linq for some security reason (I am not sure what this security linkage is but we have not to follow linq relegiously).
So I just wanted to know how entityframework works for performing all its db transaction and whether by any chance it is using linq to sql?
Hope I was able to convey my problem. Please look into this and respond ASAP. I am in a kind of fix :(
Regards
Subrat
No - both Linq-to-SQL and Entity Framework make good use of the LINQ features in C#/VB.NET - but they're both totally separate projects.
Linq-to-SQL was created by the C# team, more or less as a "proof-of-concept" for how to use LINQ with databases.
Entity Framework on the other hand grew out of the database teams (ADO.NET team) at Microsoft and was designed from the ground up as a full-fledged, enterprise-ready system to be the "next big thing" after straight up ADO.NET
Why using LINQ (as a technology) should have any security implications is beyond me.....
Yes - with the Linq-to-SQL approach, your application needs direct access to all underlying tables - read and write. But with EF in version 4, you can do very safe styles of work:
SELECT only from views exposed in the database
handle all the CUD operations (INSERT, UPDATE, DELETE) by wiring up your EF entities to stored procedures
With this, your applications don't need direct table read/write access at all - no different than when manually using SELECT from views and stored procedures for all other operations.

Linq To Entities, MVC, Creating Views

I have an application that I want to migrate to ASP.NET MVC. There are few stumbling blocks that I am not able to clear.
I am using the following components
Linq to Entities
MVC with Razor
Now I have three major hurdles.
The sql query is quite complex - I want to use it as it is (without Linq )
How to create a view that will display data from this query's resultset
the query involves joins on tables across multiple databases (though on the same server ) - what is the best approach to make it pure-linq in future.
I'm still learning the Entity Framework myself, but hopefully my answer will help you out a little with some advice and starting points.
If you have a complex sql query that you want to leave intact as is, your best bet is to add it as a Stored Procedure in your Database. You could then add/call the Stored Procedure using the Entity Framework. You can set up the model to use a stored procedure.
Using my suggestion in #1, I'd recommend you simply build a custom object to store the data in the structure you need it to be in. In your controller (or however you have your project set up for data/business logic) you can populate the object by using EF to call the Stored Procedure. You could then create your view and strongly type it against that object/model and display it in whatever manner it's needed in.
As for this question, I am not sure. However, I did do a quick search and hopefully this thread may help point you in a direction. EF4 cross database relationships

Resources