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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With