Is LINQ mostly for Select statements?
I think LINQ feels best with select statements and making a new object/record. For updating and deleting I don't feel it is really easy 开发者_Python百科or convenient. Anybody who has any views on LINQ's use?
Technically speaking, LINQ stands for "Language INtegrated Query" so by definition, yes it refers to the language extensions that enable selection, filtering, projections, etc. It does not necessarily relate to update/delete/insert/etc.
Having said that, LINQ is used more loosely to refer to various technologies like LINQ to SQL, LINQ to XML, etc which may or may not have their own mechanisms for performing update/delete/insert/etc. So for example, with LINQ to SQL the data context can track updates and perform deletes, inserts, etc but this really has nothing to do with "LINQ" in the general sense of the word. But it does make it very easy to produce a set of entities upon which you can perform those CRUD operations.
But even still, it would be quite a pain if you were to use LINQ to SQL to select records and then try to use straight ADO.NET to perform change operations. You'd just be going against the grain and for probably little benefit. LINQ to SQL/Entities does indeed let you call stored procedures if you need to use complicated TSQL to do your changes.
My primary use of LINQ is as a declarative technique for producing efficient, readable, bug-free iteration code. It doesn't matter to me if I'm testing, aggregating, or updating data with this code - or deleting either, as long as my delete operations aren't actually modifying the collection I'm iterating over. I find LINQ equally useful in all those scenarios.
But I don't use LINQ to SQL at all. I've never found a good use for it.
I can't speak for LINQ to SQL, but in general I'd agree. See “foreach” vs “ForEach” for a good discussion of this.
精彩评论