IS using DataSet is better then using LINQ to SQL Classes?
This is my first project that i need to use some database ( using SQL server 2008 ). I have the tables and now i need to decide how i will read the data from 开发者_运维技巧the tables. I define dataset and i added some Querys that will return the information that i need to get from the table.
But i can also use the "LINQ to SQL Classes" to get the information from the tables. I think that using the Dataset and/or using the "LINQ to SQL Classes" is very simple.
The questions that i have are: 1. Is there is some benefit of using DataSet or using the "LINQ to SQL Classes" ? 2. Witch of them have better performance ? 3. Is there some other reason to prefer one them instead the other ?
1) Is there is some benefit of using DataSet or using the "LINQ to SQL Classes" ?
I would argue that the idea of an ORM like Linq-to-SQL is to turn the row/column structure of a relational table (which works great in the DB) into a .NET object with properties which is just so much easier to work with than a DataSet / DataTable / DataRow / DataRow["colname"]
structure in .NET. As an added benefit, you also get intellisense on your object and its properties, and those properties are type-safe, e.g. you know from your object that Age
is an INT
property and .NET won't allow you to assign a string to that age property - with the DataRow["Age"]
, you can assign anything you want to it - you'll get the error at runtime, when you try to save. Not a great programming experience!
2) Witch of them have better performance ?
Just in terms of system performance: straight ADO.NET (DataSet etc.) will have slighly better performance mostly, since Linq-to-SQL is another layer on top of ADO.NET
In terms of programmer performance (productivity): using an ORM like Linq-to-SQL wins hands-down - no comparison!
3) Is there some other reason to prefer one them instead the other ?
I think these points are enough pro ORM:
- being able to work with objects
- getting intellisense with objects' properties
- type-safety for object properties
At least for me, this is more than enough to never ever wanting to go back to DataTable/DataRow
programming..... it's sooooo last century... :-)
精彩评论