I am starting to design a new application and what I am wondering is peoples opinions on Linq2SQL or Linq2Entities and what they feel is the better technology for rapid development.
I am also doing some research into ADO.net data services.
First off, if you're starting a new project, use Entity Framework ("EF") instead of Linq to SQL because it now generates far better SQL (more like Linq to SQL does) and is easier to maintain ("L2S").
LINQ to SQL was the first object-relational mapping technology released by Microsoft. It works well in basic scenarios and continues to be supported in Visual Studio, but it's no longer under active development.
When you want a default value is returned if the result set contains no record, use SingleOrDefault. When you always want one record no matter what the result set contains, use First or FirstOrDefault. When you want a default value if the result set contains no record, use FirstOrDefault.
We can see right away that LINQ is a lot slower than raw SQL, but compiled LINQ is a bit faster. Note that results are in microseconds; real-world queries may take tens or even hundreds of milliseconds, so LINQ overhead will be hardly noticeable.
Yes, agreed with Slace.
Just be careful on the framework you do choose, to ensure it meets all your needs.
For instance, I recently gutted out Entity Framework from a work project after working with it pretty solidly over the last couple of weeks, as it did not facilitate my needs, mainly due to:-
Other than that, commands and the framework seemed straight forward and neat, and the reason I went with EF was:
Further reading (another SO post):
Is LINQ to SQL Dead or Alive?
I would love to choose EF, I really do not know what to make of the L2S vs. EF debarcle, and if L2S really is a dead duck, shrug. my main gripe admittedly with EF is the NotSupportedException's - I could get around lazy loading if I could perform method calls in linq without getting this...
I'm a big fan of LINQ to SQL if you meet the following design requirements:
I've not done a whole lot of work with Entity Framework but from what I know and what I have done is that it doesn't have as-good performance when generated from the same database as LINQ to SQL uses.
The lower performance is due to the nature of Entity Framework, it uses ADO rather than specific providers for the database server you're using.
I would say that for a simple to moderate database schema, Linq2SQL works very well and is easier to set up and use. This is what I use for my ORM with some small adjustments through partial classes to support validation and authorization/auditing. I use the DBML designer and add my tables/relations. I change the DataContext to make it abstract and build a concrete implementation that allows me to provide implementations of my table-valued functions/stored procedures (which map into the data context as methods) that provide hooks for auditing and authorization. I implement partial methods on the entity classes for OnValidate and OnLoad to do both validation and authorization at the table level. I find that this is pretty much all I need. Lately, I've been defining an interface and wrapper for the concrete data context as well to allow me to mock it out in my unit tests.
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