3

There are lof of difference between Linq to Sql and Entity framework like Linq to SQL is one to one mapping and EF is many to many mapping and many other which can be found at Entity Framework vs LINQ to SQL

But here I am asking with EF and Linq to Sql, do we create Entities first and then generate tables or the other way and what are positives and negatives of both the approaches. In EF could there be any business entities which are inherited form multiple tables and does not represent any thing in the DB. Is Linq to Entities different from EF?

Please let me know if question is not clear or wrongly asked. Thanks in advance guys.

3 Answers 3

2

For "production" releases, both EF & L2S require that a data model (read: Database schema) be in place before any classes can be generated. The ability to create your classes first and then generate the DB from that is available in the form of the EF4 CTP that ScottGu blogged about recently.

As far as a single Entity reflecting multiple tables: I believe that is currently a one-to-one relationship: 1 table = 1 Entity.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Allen, Yes EF4 can do it both ways. When starting a new project which one should be preferred? and why.
According to Microsoft, when doing .NET 4.0, EF4 is the preferred solution for doing O/RM. Many new technologies will be placed on top of EF (WCF Data Services for instance) and while Microsoft still fixes bugs on L2S, it is not being developed anymore. Or as they call it; it is done ;-)
2

I believe with either EF 4, or an add-on, you can create your model first and have it generate your DB schema. Prior to EF 4, and with Linq-to-SQL you need to start with the DB and map the models.

3 Comments

Thanks Taylor, What is preferred approach here?
Not sure there is a "preferred approach." If you already have a DB, I'd use the Linq tools to model it in code. If you're starting a completely new project and don't have the DB, then perhaps the code first approach would be better
Indeed: The LINQ to SQL DataContext class contains a CreateDatabase method that allows you to build a database from a model. L2S does not contain a feature to generate the SQL statements for this, as the EF4 designer has. However, when you use the Log property, you'll probably get pretty close.
1

in linq to SQL you first make a database, then import it, build the app and your objects will be made.

i started to fool around with EF at first learning MVC, then at the point of starting to work with the code i used linq to SQL, and, well, it's both linq, there is no real difference in the linq queries that i can tell.

1 Comment

There certainly are differences. Especially between L2S and EF3.5. EF3.5 for instance does not support Single and SingleOrDefault. It does not know how to translate queries that have a Contain method (for instance: from c in db.Customers where ids.Contains(c.Id) select c). Besides this, the performance and readability of the L2S is much, much better. All of this was fixed BTW with EF4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.