Is LINQ mainly for Select statements?

I think LINQ is best for select and create new object / record statements. For updating and removal, I do not feel that it is really easy or convenient. Anyone who has any views on using LINQ?

+4
source share
3 answers

I can't speak for LINQ to SQL, but overall I agree. See "ForEach" vs. "ForEach" for a good discussion of this.

+1
source

From a technical point of view, LINQ means "Language INtegrated Query", so by definition, yes, this refers to language extensions that allow you to select, filter, projection, etc. This is not necessarily related to updating / deleting / pasting / etc.

Having said that, LINQ is used more freely to refer to various technologies, such as LINQ to SQL, LINQ to XML, etc., which may or may not have their own mechanisms for executing update / delete / insert / etc. So, for example, with LINQ to SQL, the data context can track updates and perform deletions, inserts, etc., but this has nothing to do with LINQ in the general sense of the word. But it’s very easy to create a set of objects on which you can perform these CRUD operations.

But even then, it would be painful if you used LINQ to SQL to select records, and then tried to use direct ADO.NET to perform change operations. You are just going to go against the grain and probably of little use. LINQ to SQL / Entities really allows you to call stored procedures if you need to use sophisticated TSQL to make changes.

+3
source

My main use of LINQ is a declarative method for creating efficient, readable, iterative, error-free code. For me, it doesn’t matter if I test, aggregate or update data using this code or delete it, if my delete operations do not actually change the collection that I am executing. I find LINQ equally useful in all of these scenarios.

But I do not use LINQ to SQL at all. I have never found good use for this.

+2
source

Source: https://habr.com/ru/post/1301270/


All Articles