0

I want to learn about Entity Framework. To query databases using that, I have to learn LINQ. My question here is that is:

Is LINQ not overly complicated? I don't see any use of it, instead I think hand-crafting SQL queries is much better.

I have spent lots of time learning ASP.NET WebForms, and it turned out that what I was worried about was actually there, so it was a waste of time. It looks like LINQ makes the same mistake ASP.NET WebForms made, by trying to facilitate the developer by rendering the html for him and impose state on stateless nature of HTTP.

So, any insights on what this LINQ and Entity Framework can do that others don't?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Your question seems to be _"Why use LINQ, aren't handcrafted SQL queries better?"_, which is opinion-based. Please explain what you actually want to know. – CodeCaster May 11 '14 at 11:01
  • @CodeCaster yes right. I think you are right in suggestion of title. I want to know should I spend time and make a few more hairs grey learning linq and entity framework? – user2638682 May 11 '14 at 12:15

2 Answers2

1

I also came from a background of using ASP.NET web forms over many years. Once introduced to MVC and razor it felt like an immediate freeing of some of the hard work that web forms, the controls, and what felt like a complex client/server model carry with them.

LINQ and Entity Framework are not part of MVC. LINQ is a genera; purpose query language that works on many levels from simple string handling to complex data processing. LINQ can also be used with lambda notation; I find the latter easier and mode natural.

EF allows you to develop all your database components from your code. I found that move away from SQL very strange at first but am very happy to have made the transition.

I think that you are asking a philosophical question. I started programming in the late 1960s and have seen many transitions and technology changes. I have found this change as valuable as any.

Peter Smith
  • 5,528
  • 8
  • 51
  • 77
  • Thanks for the reply. whichever article or book or code sample I read I see this linq thing and I always skip that portion which makes things unclear. So I think I should learn it anyway. but you can say like I am snake bitten by asp.net and now I am worried of everything microsoft offers.. but this is nice to hear that you are happy with it.. so I should lend some time to it now. – user2638682 May 11 '14 at 10:46
  • It's definitely worth it, but expect some pain. – Peter Smith May 11 '14 at 10:51
  • yes already reading and looks pretty tough and confusing.. – user2638682 May 11 '14 at 10:56
  • I had the same problems when switching from Web Forms to MVC and Web API, BUT it was definitely worth the time. I found LINQ extremely confusing at the beginning, but today I can't imagine to program without it. If you talk to Java developers and tell them about LINQ they are always amazed by it. It is hard to get started, especially you have to learn a lot of new concepts. A good place to start is the following [site](http://www.dotnet-tricks.com/Tutorial/linqlist). Best approach is to integrate LINQ at any place you can to get some hands-on. – Horizon_Net May 11 '14 at 11:49
  • well, a personal question.. what motivates you to learn such challenging things at such age? I like this attitude and am like this myself. – user2638682 May 11 '14 at 12:06
  • @Horizon_Net Ok that is great . – user2638682 May 11 '14 at 12:08
  • I found that Web Forms is a great framework, but had some big disadvantages. I worked with ASP.NET MVC since its first release and working with it is hard if you don't how LINQ works. Fortunately, I had some friends who are better developers than me and they helped me to get started with LINQ. I started with LINQ-to-SQL and thought that it was great. After this mind shift using LINQ-to-Entities wasn't that hard. Compared to the days without LINQ today I write less code to achieve the same with better performance, less errors, and more readable (f.e. you'll have less for- and foreach-loops). – Horizon_Net May 11 '14 at 12:23
  • Yes I think too that learning MVC without linq will be difficult. – user2638682 May 11 '14 at 12:25
0

WebForms wasn't that bad. It did exactly what it was built for: abstract the fuzziness of HTTP's statelessness to WinForms developers, so they could jump into the web era without changing too much of their WinForms workflow.

Entity Framework and other ORMs offer the same level of abstraction. You usually don't want to bother writing SQL by hand, connecting to the database, pulling in the query results and map those into objects. This is exactly what Entity Framework does for you, and yes, you'll have to learn LINQ to do the querying (though you can still use SQL).

You can use LINQ for much more, it's not tied to databases in any way. It's the other way around: EF allows you to express your query in statically-typed code, where at runtime those queries will be converted to the appropriate SQL.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • I think your explaination of the asp.net webForms is making sense. But anyway it is fraught with bad ideas and designs and the simple task was made complicated beyond limits with webControls and viewState which puts limit on ajax activity on a page. I have developed a whole social network with asp.net WebForms and now I have to rewrite it either in asp.net MVC or PhP because I want multiple ajax activity at the same time. so I wanted to know that linq might not be designed with such silly Ideas. – user2638682 May 11 '14 at 12:33
  • As long as you follow the mindset of the creators of any library, you won't run into any trouble. WebForms was not built for what you tried to do with it, so it was hard. Entity Framework can cause specific problems when you want to do stuff it wasn't designed for, but it's easily avoided when that happens, by bypassing the LINQ-to-SQL part and querying manually. There's little blame to put on LINQ itself and it's worth learning it, as it's usable in various parts of the .NET framework and third-party libraries. – CodeCaster May 11 '14 at 12:35
  • and sorry I did not mention asp.net Ajax :D :D :D :D and yes you are right and that is what I want to know exactly what is the logic and limits behind something but I never get it from someone till I fall headlong. :( – user2638682 May 11 '14 at 12:42