Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 383
James Hulse Avatar asked Jul 28 '10 23:07

James Hulse


1 Answers

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.

like image 164
Reed Copsey Avatar answered Sep 30 '22 02:09

Reed Copsey