Linq To SQL: a newbies Journey
I am new开发者_JAVA百科 to asp.net and I am trying to learn Linq to SQL. So I have found two different ways to pull from the database. The normal linq to SQL way and the direct SQL statement way.
I have both working, but I want to know which way is the accepted standard? I want to use straight SQL statements, because that is what I am use to, but I am trying to go with whatever is best practice.
Thanks
Take a look at the selected answer to this popular question.
Entity Framework became the preferred way to interact with a SQL database in ~2008. Much of the heavy lifting in database calls and transactions is greatly simplified in EF.
If you continue to use Linq to SQL and want to learn from the master, have a look at Scott Guthrie's Post.
Entity Framework is to be Microsoft's best practice solution. Once you learn LINQ you will find it is much easier to code.
Personally, I much prefer using LINQ and have since the moment I learned it. You can turn on the log feature while you are learning and can see the SQL that gets created. If you have performance concerns and need to hand tweak SQL you can always revert to that. Just not having to hard code strings with table and field names makes code more maintainable and with intellisense also much more enjoyable to write.
There isn't really an accepted standard between straight SQL and LINQ (or any other ORM). It depends on what environment you're using it in, and what you want to do. However, Microsoft has announced that the LINQ to SQL project isn't going to be continued, so I suggest you consider the ADO.NET Entity Framework (which supports LINQ via LINQ to Entities) instead.
Refer to the following:
ADO.NET and LINQ to SQL
Advantages & Disadvantages of LINQ
Performance of LINQ to SQL over Normal Stored procedure
LINQ-to-SQL and Stored Procedures
精彩评论