question

RodFalanga avatar image
0 Votes"
RodFalanga asked DuaneArnold-0443 commented

Where is the processing performed by EF6?

I'm on a team working on developing new Windows applications. We use EF6.

At this point I'm still working from home. I've noticed that under certain circumstances, the query I run using EF6 can take 1 to 2 minutes to finish. It's querying four tables together using Include statements and Select to get a grandchild table. However, it doesn't run that slow for other colleagues. For some of them it runs acceptably fast.

Nevertheless, I'm concerned that performance for the users might be unacceptable. In thinking about this I can see various places where the performance might be affected.

  • My ISP (although I do have fast connection for my state)

  • The work laptop I'm using (it's older)

  • I am pulling down 38K records

This got me to wondering, when using EF6 where is the processing of a query performed? Does it happen at the server? Or is EF6 doing the heavy lifting on the client's machine?

dotnet-entity-framework
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@RodFalanga It seems to depend on where you execute the EF query.

0 Votes 0 ·
DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered DuaneArnold-0443 edited

@RodFalanga

Of course, the EF generated T-SQL runs at the database level. It's going to run as fast as if you had taken the T-SQL and executed it using SSMS. But EF is an ORM, and objects must be materialized and sent back in a tubular form using a collection and this takes time when using Linq.

If the Windows desktop application using EF and the database is local to the client machine, there is not going to be much of a performance impact.

If the database is on a network and database access application using an application server that is using EF, there can be performance issues seen by the client.

https://docs.microsoft.com/en-us/ef/ef6/fundamentals/performance/perf-whitepaper


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RodFalanga avatar image
0 Votes"
RodFalanga answered DuaneArnold-0443 commented

All the applications we write are 2-tier applications. So, the EF queries are always run in the client. By that I mean that the instantiation of DbContext and DbSets always happen in the client. Any queries also happen there. Everything using LINQ and entities happens in the client.

Does that mean that the database queries are performed on the client? Or does EF6 construct the SQL statements, then send those to the SQL Server database where they are executed, sending the resultsets back to EF in the client for formatting it as the LINQ statement specifies?

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


If there is not MS SQL Server Express using LocalDB installed on the client machine and EF is using LocalDB, then the generated T-SQL queries submitted to the database engine by EF are not running locally on the client machine.

If the database server machine is using MS SQL Server on a dedicated Windows O/S server platform, then EF is submitting the generated T-SQL to the DB server engine over the network.

The only code running on the client machine that I know about is Linq-2-Entities with EF to materialized the model objects used by the program.

https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ee658117(v=pandp.10)

1 Vote 1 ·

All our applications work against a MS SQL Server database on a domain server. So, sounds like the heavy lifting is being done by the server, not the client. That's certainly good! BTW, here's the URL again: https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ee658117(v=pandp.10)

I'm not sure what you mean by "The only code running on the client machine that I know about is Linq-2-Entities with EF to materialized the model objects used by the program."


0 Votes 0 ·

The client program can be a Windows desktop or an ASP.NET Web program in their simplest example definition of what program type is using EF and is considered to a client program running on a client machine, which is a client to the database server with the client program implementing and hosting the ADO.NET Entity Framework an ORM.

https://docs.microsoft.com/en-us/ef/ef6/fundamentals/working-with-dbcontext

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ef/language-reference/linq-to-entities

ORM's virtual object model is aka the ORM's conceptual object model, which are those classes/objects (data containers) that allows the client program to do CRUD operations using the (data container) objects with the database tables while using EF.

https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapping





1 Vote 1 ·