Linq Include in MVC application
I have an SQL query with joins. I want to use Linq. some one suggested me to avoid jo开发者_开发知识库ins and use Linq include. How can I combine entities using Linq include? Is there a better way than joins ?
Thanks
LINQ to SQL converts LINQ syntax to an SQL query. If the query requires a Join, then LINQ to SQL will actually execute an SQL query with joins against the database. The advantage you may gain is that the LINQ to SQL query may be more optimized than the one you have written.
If you are not familiar with using LINQ and you have a working application, you will probably not gain anything other than complication by adding an additional layer of abstraction (LINQ). That being said, LINQ is an excellent and powerful tool. However, that doesn't change the truth to the adage "If it ain't broke don't fix it."
Basically, what you are considering is converting your application's data access procedure from
app -> SQL Query with Joins -> data objects
to
app -> LINQ Query with Joins -> SQL Query with Joins -> data objects
I am pretty well versed in both, and I think writing LINQ queries is a lot easier than writing SQL queries. (You get strongly typed models and Intellisense). However, if you only know SQL, then writing an SQL query is significantly easier than learning LINQ and writing a LINQ query .
Note that LINQ also supports joins. Here is an article on using joins in LINQ: http://odetocode.com/Blogs/scott/archive/2008/03/25/inner-outer-lets-all-join-together-with-linq.aspx .
精彩评论