Can someone please clarify the key difference between Entity Framework and Typed Datasets?
Asked Answered
S

4

6

I am comparing the EF and typed datasets for their usefulness. I was failing to see why you would use the EF over typed datasets if the EF is bound to SQL Server only. But is it true that the Linq statements in EF are evaluated late in the respect that if you did something like:

db.Customers.where(c => c.Name == "John Smith")

The EF would build up a query like:

select * from Customers where Name = 'John smith'

But with Typed datasets you could write:

bll.GetCustomers().where(c => c.Name == "John Smith")

Which is very similar but the difference is it first runs:

select * from Customers

And then using the standard collections library finds the rows which contain the Name: "John Smith". In theory meaning the EF will be more efficient.

Is this correct?

Scrunch answered 28/7, 2010 at 23:1 Comment(2)
Good simple question illustrating a point that may not be immediately obvious.Etka
EF - Good, Typed Datasets - Blaaaaah.Egocentrism
A
4

Yes. With Entity Framework, it's using IQueryable<T> to construct your queries. By doing:

var results = db.Customers.Where(c => c.Name == "John Smith");

Internally, the results will be IQueryable<Customer> (or your type). This allows the provider (EF) to optimize how that is executed internally. In the case of SQL Server, the actual query sent to the server will have the SQL WHERE clause in place already, which in turn will mean you'll only return a single record (if "Name" is unique) back from the DB instead of every record.

Using typed datasets, you'll return every record, then search the results for the appropriate Name afterwards. This is potentially much less efficient.

Alboran answered 28/7, 2010 at 23:14 Comment(2)
Great, this was just the kind of answer I was looking for :) Now to work out whether I use the EF as my data access layer or abstract it with another layer on top of it...I kind of like the idea of using Linq in my business logic layer. (But this is probably a question for later) Thanks !Scrunch
How about if you have stored procedures where you are passing parameters to get records you need instead of returning all. It depends how you use Typed Datasets.Varicelloid
S
2

That is correct. Entity Framework is an Object-Relational Mapper (ORM). It provides a way to map your objects to a relational data for querying. IQueryable<T> is used with EF and can basically optimize the SQL that is sent to and from the server.

Sabra answered 28/7, 2010 at 23:16 Comment(0)
E
1

No, it's not correct. Using typed datasets you would add a parameter query to the tableadapter such as 'SELECT * from Customers where name = @name' You would supply the name parameter from your code at runtime. That way you would only pull the data you want into the dataset. Pulling the entire table first as per Reed's reply would be wildly inefficient at best and not realistic with a database of any size. This seems to be a common misunderstanding of ADO.Net, perpetuated even in some books - especially books about Entity Framework!

Errant answered 5/1, 2013 at 18:47 Comment(1)
Correct, you are rightVaricelloid
V
0

There are ways to use Typed Datasets in an efficient way, Parameterized your stored procedures and on top of that use Paging at Stored Procedure level, that will be much faster.

Varicelloid answered 28/10, 2023 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.