![]() Overview of SQL syntax These topics provide an overview about how to use the SQL statements, SPL statements, and syntax segments.Guide to SQL: Syntax The HCL OneDB™ Guide to SQL: Syntax describes the syntax of the statements, data types, expressions, operators, and built-in functions of the HCL OneDB™ dialect of the SQL language.SQL programming You can use the HCL OneDB™ implementation of the SQL language to develop applications for HCL OneDB™ database servers.IEnumerable has a methods GetEnumerator(),Current() and MoveNext(). If you are querying against the in process data then.If you are writing the query against the data in the database then.In this IQueryable it will execute the two Queries at the same time in the sense it will get the population which is of top 10 in a single Query instead of getting the data and filtering the first 10 again.(One time execution on sql server).Ĭonclusion for IQueryable and IEnumerable IQueryable _Population=from s in India select s.population //First Query If we execute the same query by using IQueryable. ![]() ![]() Now if we execute this query First Query will be executed first the IEnumerable will get the Records of all the population from the sql server then it will store the data in the In Process memory and then it executes the top 10 population in the next Query.(Execution is taken place for two times on sql server). _Population=_Population.take(10) //Second Query IEnumerable will first Executes the first query and then executes the sub queries written for that query.Įxample: If you want get the top 10 population Records from a Particular country then the query we will use in LINQ is IEnumerable _Population=from s in India select s.population //First Query IQueryable,IList,IDictionary,ICollection inherits IEnumerable Interface.Īll the interfaces of type collection will inherits IEnumerable Interface.ĭifferences Between IEnumerable and IQueryable IEnumerable: Wen you are running a query which returns of type IEnumerable. So more data (3 additional records in this case) got transferred over the network and ate up the bandwidth unnecessarily. Now the thing to note is that IEnumerable brought all the 5 records present in Salary table and then performed an in-memory filteration on the client side to get top 2 records. Query text captured in SQL profiler: SELECT. ![]() IEnumerable employees = from e in efContext.Employees select e.Salary No more in-memory filtering is required on the client side.Ĭase II: Code for IEnumerable route using (var efContext = new EfTestEntities()) So it brings only 2 out of 5 records over the network. We can see that IQueryable is smart enough to apply the Top (2) clause on database server side itself. IQueryable employees = from e in efContext.Employees select e.Salary īefore running this program, I had started a session of SQL Query profiler on the SQL Server instance. Now I can start writing LINQ queries.Ĭase I: Code for IQueryable route using (var efContext = new EfTestEntities()) Then, I added an ADO.NET Entity Data Model XML (EDMX) item pointing to Employee table in the database. I created a new C# console application in Visual Studio (VS). Now my goal was to get top 2 records from Employee table in database. Here is the record insertion script (DML script): INSERT INTO. I created following structure in DB (DDL script): CREATE TABLE. Later on, I thought to write a more detailed post to connect some missing dots.ĭisclaimer: I don't intend to cater OP's question in entirety but I want to point out the difference between IQueryable and IEnumerable when using LINQ to SQL. I've mentioned those issues in comment area of his post. I noticed few issues in gunny229's answer. The MSDN documentation for each of these is decent, so I would start there in rounding out your understanding. It is also enumerable in that you can enumerate the key/value pairs, but otherwise it serves a different purpose than the others you listed.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |