+6  A: 

With EF you get a mapping layer (i.e. your entities) between your class objects and your database tables. If you need that kind of flexibility, or prefer a domain-driven design model (as opposed to a table-driven design), EF might be worth considering. Linq to SQL is pretty much a class-to-table mapper.

Robert Harvey
So, to try and clarify for myself, you are saying, as an example, that if I have DB's that I have no control over EF will allow my to make classes that make sense for my app irregardless of the table structure where as L2S will not?
Refracted Paladin
@Refracted: For the most part. Obviously EF will not make up for a really bad database design, but it can smooth things over considerably. Also, some people prefer a domain-based design, where the underlying tables can, in fact, differ from the actual domain objects.
Robert Harvey
@Robert Harvey: So would it be fair to say that since I design all DB's, besides the aforementioned inherited ones, that EF's benifit in this area is minimal? That is unless of course I design a crappy DB and then try to use it.
Refracted Paladin
Correct, if your design is table-based, and you are comfortable with direct mapping of tables to objects, you should feel good about continuing to use Linq to SQL. If you ever need EF for mapping work, or to hook up to another database that is not SQL Server, you can always add an EF data context to your solution.
Robert Harvey
Most people prefer to think in terms of objects, not in terms of tables.
BlueRaja - Danny Pflughoeft
@BlueRaja: I didn't see that study. I'm an old-school SQL database programmer, so I prefer thinking in terms of tables for data persistence, especially for small applications. But, to each his own.
Robert Harvey
When you get into bigger applications, having to constantly worry about the database becomes a **major** pain. In a good, correctly setup O/RM (like NHibernate), you should not even have to think about the database while coding - it handles itself. Of course, Entity Framework is nowhere near this level yet.
BlueRaja - Danny Pflughoeft
A: 

Well, at the end depends on requisites.

Now you uses linqtosql and it is right for you, but maybe one day you have more sophisticated requisites that you can better complish with EF. For instance using velocity or whatever.

Pablo Castilla
No offense but you are essentially restating my question. I understand that EF allows more "sophistication" what I don't understand is WHAT?
Refracted Paladin
Well, basically you have this three: session in a ORM fashion, entity first scenario and distributed caché.
Pablo Castilla
+2  A: 

I've often wondered this myself as EF seems to add a lot of complexity over L2S. Since MS is actively developing EF, there are some new aspects of EF 4 that may be worth checking out. There is a nice summary on the ADO.NET team blog that describes how the API for EF is evolving to support a wider range of development patterns.

In particular, I'm personally interested in support for POCO and the repository pattern as they are a nice fit for the projects I work on. In my opinion, one compelling reason to use any particular provider is how easy it will be to switch to a completely different provider in the future (without overhauling all of your application code, of course). I find L2S lacking in this respect (out of the box, anyways), and I'm happy to see the changes in EF 4. So far, however, I have only been reading about these changes in EF 4, so I can't say how well they actually work in practice.

Michael Petito
A: 

I asked myself this question when I first saw EF and I'd already written a large application in Linq2Sql. The biggest change is done in the object mapping layer. In EF relationships and navigation is managed for you. So if I have two tables that have a foreign key relationship (say Pets and Owners) I can do

pet.owner

whereas in L2S I'd have to write the join query myself. Many-to-many mappings are handled sweetly in that if you have a 'pure join table' (that is a table with the two foreign keys and no other data) then this table is not represented in the object mappings.

You can also handle eager/lazy loading yourself.

I can also develop in POCOs so I'm not tied to the framework directly i.e. I don't have all the noise of the L2S or the EF types getting in the way, this makes testing way easier.

Overall I much prefer EF but YMMV

Kevin Jones
Great answer! I am curious though, and I will try and verify this myself, but, as to, your point about `pet.owner` I thought that was also possible in L2S. I could be mistaken and I am going to go look in my code where I thought I was doing that. Your other points, though, seem quite valid and have me thinking.
Refracted Paladin
pet.owner - possibly - it's a while since I used it - I'd have to go back and check, maybe somebody else can confirm
Kevin Jones
@Refracted: If a relationship exists between the two tables in the Linq to Sql designer, you can indeed reach through the `pet` object in this manner, and grab the `owner`.
Robert Harvey
@Robert Harvey: Thanks, though I am pretty much back to square one, now, on my question.....
Refracted Paladin
-1 This is misleading. If L2S knows about your table relationships then they are indeed mapped as properties in the same way as EF.
Kirk Broadhurst
A: 

Entity Framework has better compatibility if you expect your application to scale on other DBMS, that's one of it's main advantage.

Entity Framework will work on DBMS other than Microsoft SQL Server, like Oracle, MySQL etc.

While Linq is limited to MS SQL Server.

GenEric35
Thanks for the answer but if you'll notice, in my original post..."*We ALWAYS use SQL Server as our Database backend.*" So that is not really a plus for me in this case.
Refracted Paladin
Linq to SQL then
GenEric35
A: 

L2S allows for implicit lazy loading while the EF has explicit lazy loading. In a small project the implicit work done in L2S is certainly nice and good for rapid development & changes to the model but in larger projects, developers may want more control over what database resources the app is calling.

See http://www.singingeels.com/Articles/Entity_Framework_and_Lazy_Loading.aspx

Nick Gotch
Not true any more. In EF 4 you can decide lazy or eager.
Hightechrider
+2  A: 

EF is geared to be an all out ORM where your object model is significantly different then your DB schema. L2S is more aimed at being a quick DAL generator.

The problem is that EF is a mediocre ORM, while L2S is a really great DAL generator.

I would say if L2S fits your needs, stay with it and don't let MS marketing push you around. If L2S doesn't do what you need it to do, and you need to stay in microsoft products, go with EF. If you have a bit of freedom over your technology, look into NHibernate and LLBGen (imo both are better then EF)

Matt Briggs
A: 

I made the switch from Linq2Sql to Entity Framework some time ago for all my projects. Initially it was a step backward in several regards - date expressions that worked just fine in Linq2Sql didn't work in EF and there was no lazy loading option. But now, with Entity Framework 4 everything works smoothly.

If it's just you and you don't have time to learn EF, stick with Linq2Sql. But if you do have time and think you might eventually want other forms of inheritance than -per-table, or any of the other features of EF, go for it!

And the #1 reason you should make the switch: Entity Framework experience will look good on your resume!

Hightechrider
+1  A: 

They are both very buggy. I've found 8 bugs in Entity Framework since I started using it a month ago (two affect L2S, at least three are still present in EF4). It has been one of the most painful experiences of my life.

The separation of classes and tables would be really nice, though, if EF worked the way they wanted it to.

BlueRaja - Danny Pflughoeft
+2  A: 

I big reason not to use Linq2SQL is that it has a significant implcit design flaw:

The recommended best practice for using a DataContext is that it be used in a short lived "unit of work" style. Great, except that it's a moderately expensive object to keep creating and disposing of in the first place.

The snag comes in when you want to deserialize or recreate an object (perhaps, from a submitted web page) and then update an existing record. The Attach method offered by the Linq-to-sql will only accept the following three scenarios:

  1. You implement timestamps on all your tables.
  2. You re-select the entity you want to change, then change it and submit.
  3. You magically just happen to still have the original version of the object around.

The first scenario requries database changes, which for some environments is unacceptable. The second scenario is down-right inefficient - why retrieve data you already have? The third scenario is un-realistic - stateless web apps don't typically retain historic information.

The point here is... EF4.0 allows you to reattach an object to an ObjectContext and mark it as added or new, and the context will generate the correct INSERT/UPDATE statement accordingly.

Mark
How has this not been voted up? Best answer by far.
FerretallicA