MiniProfiler EF6 - Misleading "duplicate" queries - entity-framework-6

I'm using MiniProfiler EF6 (3.0.10-beta4) on an MVC5 project with EF 6.1, and it's showing a number of "duplicate" entity framework queries in its output.
The parameters to the "duplicate" queries are identical and I've traced the call to one common location in my code where the query is executed, and I can see that the EF query is definitely being called multiple times.
However, when I use SQL Server Profiler to monitor the queries that are actually getting executed on the database, the query that MiniProfiler says is a duplicate only got sent to the database one time; all subsequent executions of that query were against the cached results in the DbContext.
Is this a new bug? I found an old StackOverflow question that sounds like the same issue, but it was reportedly fixed a long time ago.

Related

Getting SQL queries generated with Entity Framework Plus?

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);

EF 6 DB First Audit Logs

I have a EF 6 DB first MVC 5 application. My requirement is to do audit logging of every operation (including read). I went through many posts and have few queries:
Should audit logging be done at EF level (by overriding SaveChanges) or DB level (by using triggers). Which is the recommended way.
I want to log one row per entity change instead of per property change. What am I thinking is to make a valid XML schema but then each entity will have different schema depending on the column. Any other inputs on how to achieve this
I want log for read operation too
Last thing is, client wants to maintain checksum value per row using SHA3 or MD5.
Considering above points, what is the suggested approach. I could really use some pointers.
To achieve this, I did not use any utility as my requirements were bit different. Finally I went ahead with overriding the SaveChanges method of DbContext used by EF. Also used Newtonsoft JSON library to convert whole updated object to JSON and save it.
To get complete code, check this link - How to audit MVC app which used EF DB first approach

EF7 and breeze.js - batch and save order

I am embarking on a new project requiring online/offline mobile sync. I am going to give Breeze a go.
There seems to be some issues with EF6 oDATA on web 2 API (according to the breeze site with relation to batch transaction and save order.
From what I can gather, these are addressed, at least to some extent in the EF7 betas. Can anyone advise;
Does Breeze work out of the box with EF7
If not, can it be made to play nice, and how (link OK)
Does EF7 actually address the issues with batch transactions and save order in WebAPI2
Is there actually a workable solution to the issue with the edm for oData4?
We definitely will support EF7 but are unlikely to release anything before EF7 gets out of beta. As for EF6 OData, we plan on releasing an update on this within the next month.

Handling multiple updates to the same row at the same time in an asp.net mvc website using linq to sql

I am using linq to sql as ORM for my asp.net mvc website.
I dont know how will linq to sql behave in the following situation.
Suppose one of the action from a active session, modifies a row of a table
and before saving the changes to the database, I mean before calling _db.SubmitChanges() another action from some other session tries to access the same row. I am sure linq to sql
will not allow me to get that row, because that's not the updated data.
So my question is, what will happen in such scenario?
How to deal with such scenario?
I have never received an error yet, because my website is still in development
stage, and there are not many sessions at any given time.
You will be able to access the original row, up until SubmitChanges() is called, at which point the row will be locked briefly before becoming available again.
you can read about optimistic concurrency control and linq here

EF4 cross database relationships

I was wondering if EF4 support cross-databse relationships? For instance:
db1
Author
Id
Name
db2
Posts
Id
Content
db1.Author.Id
What ideally I need to do to get this relation in my ef4 model?
Do you guys have any idea?
Thanks
I've found this entry in Microsoft Connect that answers the question about the support given at this moment by EF (actually it is not supported yet).
Also found a thread in Social MSDN about this concern.
Other links on Stack Overflow:
ADO.Net Entity Framework across multiple databases
Entity framework 4 and multiple database
In summary, the only given alternatives are:
Using views in EF
Use NHibernate instead
If your database supports Synonyms, you can trick EF to span multiple databases. I wrote up how to do it here.
Basically you end up with an edmx file per database, and a script which merges them into a single edmx file. Synonyms are used to reference one database from another by using the actual table name, so EF doesn't throw a fit when you try to access database2.table from database1. You still have to setup links between the two databases manually in the EF model, but once setup they'll stay even if you re-run the merge script.
Scripts to setup Synonyms and to merge the edmx files are posted in the link
I recently began a project that uses entity framework with two databases, one Oracle and one SQL Server. I could not find any information regarding cross-database or multiple database support in the entity framework.
Most posts from the MS Entity framework team are a couple of years old and indicate that including two databases in a single model is not a feature that will be included soon. I would be interested in having a concrete answer on whether it was included in 2010 myself although I suspect the answer is no.
Currently out project gets around this limitation by having a separate entity model for each database. This has solved the problem for the majority of the scenarios we've encountered thus far in the project.
In cases where we've needed to query the data from the two databases at the same time, we simply created a view in one or the other databases. Since we're using Oracle and SQL Server, this view would utilize either a Linked Server (SQL) or a DBLink (Oracle).
The disadvantage of views in the entity framework is we've had to spent more time than I expected getting the primary keys working.
Hope this helps.

Resources