简体   繁体   中英

Do LINQ “queries” get compiled into actual SQL stored procedures?

I'm an ASP.NET n00b and I read in my ASP.NET book that your C# LINQ code gets made into actual SQL queries when you compile your project. I can't find anything on the internet to verify this; however, if it's true, I'm wondering if stored procedures are created from LINQ queries; and if not, what's the point of LINQ? I'm confused about why someone who knows how to write SQL would invest time learning something that's "valid C# and looks like SQL but isn't quite SQL" ...

I saw a related thread LINQ queries vs Stored procedures but it was written in 2011.

No, LINQ queries to databases do not get converted to stored procedures. They would be converted to SQL if the underlying database language is SQL, for example SQL Server / Oracle.

You are confusing ORM and LINQ. LINQ is more than querying database. It is also about querying general collections like arrays/List<T> ( IEnumerable<T> ).

Adding to above answer, LINQ is feature of .NET Framework which are strongly typed which aren't specific to Entity Framework (ORM) and even INDEPENDENT to database. There are different LINQ provider ie LINQ to Entities is responsible to translating LINQ to appropriate query on data and get result back.

So this will shine for someone who don't know SQL yet and who wants to deal table and data in terms of object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM