LINQ Interview Questions & Answers(LINQ面試問答)

What is Language Integrated Query (LINQ)?

什麼是語言集成查詢(LINQ)?

LINQ is a programming model that is the composition of general-purpose standard query operators that allow you to work with data, regardless of the data source in any .NET based programming language. It is the name given to a set of technologies based on the integration of query capabilities into any .NET language

LINQ是一種編程模型,由通用標準查詢運算符組成,可讓您使用數據,而無需考慮任何基於.NET編程語言的數據源。它是基於將查詢功能集成到任何.NET語言中的一組技術的名稱。

What are LINQ query expressions?

什麼是LINQ查詢表達式?

A LINQ query, also known as a query expression, consists of a combination of query clauses that identify the data sources for the query. It includes instructions for sorting, filtering, grouping, or joining to apply to the source data. The LINQ query expressions syntax is similar to the SQL syntax. It specifies what information should be retrieved from the data source.

LINQ查詢(也稱爲查詢表達式)由查詢子句的組合組成,這些子句標識了查詢的數據源。它包括有關對源數據進行排序,過濾,分組或合併的說明。 LINQ查詢表達式語法類似於SQL語法。它指定應從數據源檢索哪些信息。

Why LINQ is required?

爲什麼需要LINQ?

LINQ is required as it bridges the gap between the world of data and world of objects.

需要LINQ,因爲它彌合了數據世界與對象世界之間的鴻溝。

What are the types of LINQ?

LINQ的類型是什麼?

LINQ to Objects

LINQ to XML

LINQ to Dataset

LINQ to SQL

LINQ to Entities

Explain how LINQ is useful than Stored Procedures?

解釋LINQ比存儲過程有用的理由?

Debugging: It is difficult to debug a stored procedure but as LINQ is part of.NET, visual studios debugger can be used to debug the queries

Deployment: For stored procedure, additional script should be provided but with LINQ everything gets compiled into single DLL hence deployment becomes easy Type Safety: LINQ is type safe, so queries errors are type checked at compile time

調試:調試存儲過程很困難,但是由於LINQ是.NET的一部分,因此可以使用Visual Studio調試器來調試查詢。

部署:對於存儲過程,應提供其他腳本,但使用LINQ時,所有內容都被編譯到單個DLL中,因此部署變得容易。類型安全:LINQ是類型安全的,因此在編譯時將檢查類型的查詢錯誤

List out the three main components of LINQ? Explain what is the extension of the file, when LINQ to SQL is used?

列出LINQ的三個主要組成部分?說明當使用LINQ to SQL時文件的擴展名是什麼?

Three main components of LINQ are

Standard Query Operators

Language Extensions

LINQ Providers

The extension of the file used is .dbml

LINQ的三個主要組成部分是

標準查詢運算符

語言擴展

LINQ提供者

使用的文件擴展名是.dbml

Define what is Where clause and Let clause?

定義什麼是Where子句和Let子句?

Where clause: It allows adding some conditional filters to the query.

Let clause: It allows defining a variable and assigning it a value calculated from the data values.

Where子句:它允許向查詢添加一些條件過濾器。

Let子句:它允許定義一個變量併爲其分配一個根據數據值計算得出的值。

Write the basic steps to execute a LINQ query.

編寫執行LINQ查詢的基本步驟。

The following are the three basic steps to execute a LINQ query:

Obtain the data source (The data source can be either an SQL database or an XML file)

Create a query

Execute the query

以下是執行LINQ查詢的三個基本步驟:

獲取數據源(數據源可以是SQL數據庫或XML文件)

創建查詢

執行查詢

Write the basic syntax of a LINQ query in Visual Basic as well as in C#.

在Visual Basic和C#中編寫LINQ查詢的基本語法。

In Visual Basic, the basic syntax of a LINQ query starts with the From clause and ends with the Select or Group By clause. In addition, you can use the Where, Order By, and Order By Descending clauses to perform additional functions, such as filtering data and generating the data in a specific order.

In C#, the basic syntax of a LINQ query starts with the From clause and ends with the Select or group by clause. In addition, you can use the where, orderby, and Orderby descending clauses to perform additional functions, such as filtering data and generating the data in a specific order.

在Visual Basic中,LINQ查詢的基本語法以From子句開始,以Select或Group By子句結束。另外,您可以使用Where,Order By和Order By Descending子句來執行其他功能,例如過濾數據和按特定順序生成數據。

在C#中,LINQ查詢的基本語法以From子句開始,以Select或group by子句結束。此外,您可以使用where,orderby和Orderby降序子句來執行其他功能,例如過濾數據和按特定順序生成數據。

In which statement the LINQ query is executed?

LINQ查詢在哪個語句中執行?

A LINQ query is executed in the For Each statement in Visual Basic and in the foreach statement in C#.

在Visual Basic中的For Each語句和C#中的foreach語句中執行LINQ查詢。

In LINQ, lambda expressions underlie many of the standard query operators. Is it True or False?

在LINQ中,lambda表達式是許多標準查詢運算符的基礎。是對還是錯?

It is true.
是真的。

Explain why SELECT clause comes after FROM clause in LINQ?

解釋爲什麼SELECT子句在LINQ的FROM子句之後出現?

With other programming language and C#, LINQ is used, it requires all the variables to be declared first. ‘FROM’ clause of LINQ query defines the range or conditions to select records. So, FROM clause must appear before SELECT in LINQ.

與其他編程語言和C#一起使用的是LINQ,它要求首先聲明所有變量。 LINQ查詢的“ FROM”子句定義了選擇記錄的範圍或條件。因此,FROM子句必須出現在LINQ的SELECT之前。

Explain what is the use of System.XML.Xlinq.dll?

解釋一下System.XML.Xlinq.dll的用途是什麼?

System.Data.Dlinq.dll provides the functionality to work with LINQ to SQL

System.Data.Dlinq.dll提供了使用LINQ to SQL的功能

Explain what is lambda expressions in LINQ?

解釋LINQ中的lambda表達式是什麼?

Lambda expression is referred as a unique function use to form delegates or expression tree types, where right side is the output and left side is the input to the method. For writing LINQ queries particularly, Lambda expression is used.

Lambda表達式被稱爲用於形成委託或表達式樹類型的唯一函數,其中右側是方法的輸出,左側是方法的輸入。特別是在編寫LINQ查詢時,使用了Lambda表達式。

Explain how LINQ with databases can be used?

解釋如何與數據庫一起使用LINQ?

LINQ supports XML, SQL, Dataset and Objects. Through LINQ to objects or LINQ to Datasets one can use LINQ with other databases. The objects and datasets take care of database particular operations, and LINQ only needs to deal with those objects and not the database operations directly.

LINQ支持XML,SQL,數據集和對象。通過對對象的LINQ或對數據集的LINQ,可以將LINQ與其他數據庫一起使用。對象和數據集負責數據庫的特定操作,而LINQ只需要處理這些對象,而無需直接處理數據庫操作。

Explain what is the difference between Skip() and SkipWhile() extension method?

解釋一下Skip()SkipWhile()擴展方法有什麼區別?

Skip() : It will take an integer argument and from the given IEnumerable it skips the top n numbers
SkipWhile (): It will continue to skip the elements as far as the input condition is true. It will return all remaining elements if the condition is false

Skip() :將接受一個整數參數,並從給定的IEnumerable中跳過前n個數字
SkipWhile ():只要輸入條件爲真,它將繼續跳過元素。如果條件爲假,它將返回所有剩餘的元素

In LINQ how will you find the index of the element using where () with Lambda Expressions?

在LINQ中,如何使用帶Lambda表達式的where ()查找元素的索引?

In order to find the index of the element using where () with the lambda expression
Where ( ( i, ix ) => i == ix);

爲了使用帶有lambda表達式的where ()查找元素的索引

Where ( ( i, ix ) => i == ix);

Explain how you can assign a lambda expression to a delegate?

解釋如何將lambda表達式分配給委託?

To assign a lambda expression to a delegate
Delegate int del (int i);
Del myDelegate=x=>x*x;
Int j = myDelegate (4); //j=16

將lambda表達式分配給委託

Delegate int del (int i);
Del myDelegate=x=>x*x;
Int j = myDelegate (4); //j=16

Explain what is the difference between Statement Lambda and Expression Lambda?

解釋Statement Lambda和Expression Lambda有什麼區別?

表達式Lambdas在表達式樹的構造中被廣泛使用。要創建表達式樹,不能使用語句Lambdas。

Expression Lambdas are extensively used in the construction of Expression Trees.To create expression trees statement lambdas cannot be used

What is PLINQ?

什麼是PLINQ?

PLINQ stands for Parallel Language Integrated Query. It is the parallel implementation of LINQ, in which a query can be executed by using multiple processors. PLINQ ensures the scalability of software on parallel processors in the execution environment. It is used where data grows rapidly, such as in telecom industry or where data is heterogeneous.

PLINQ also supports all the operators of LINQ. In addition, you can query 'collections by using PLINQ. It can also run several LINQ queries simultaneously and makes use of the processors on the system. Apart from this, PLINQ uses parallel execution, which helps in running the queries quickly. Parallel execution provides a major performance improvement to PLINQ over certain types of legacy code, which takes too much time to execute.

PLINQ代表並行語言集成查詢。它是LINQ的並行實現,其中查詢可以通過使用多個處理器來執行。 PLINQ確保執行環境中並行處理器上軟件的可伸縮性。它用於數據快速增長的地方,例如在電信行業中或數據異構的地方。

PLINQ還支持LINQ的所有運算符。另外,您可以使用PLINQ查詢“集合”。它還可以同時運行多個LINQ查詢,並利用系統上的處理器。除此之外,PLINQ使用並行執行,這有助於快速運行查詢。並行執行相對於某些類型的遺留代碼爲PLINQ提供了重大的性能改進,這需要花費太多時間才能執行。

What is the function of the DISTINCT clause in a LINQ query?

LINQ查詢中DISTINCT子句的功能是什麼?

The DISTINCT clause returns the result set without the duplicate values.

DISTINCT子句返回沒有重複值的結果集。

What is the DataContext class and how is it related to LINQ?

什麼是DataContext類,它與LINQ有什麼關係?

After you add a LINQ to SQL Classes item to a project and open the O/R Designer, the empty design surface represents an empty DataContext class ready to be configured. The DataContext class is a LINQ to SQL class that acts as a conduit between a SQL Server database and the LINQ to SQL entity classes mapped to that database. This class contains the connection string information and the methods for connecting to a database and manipulating the data in the database. It is configured with connection information provided by the first item that is dragged onto the design surface.

將LINQ to SQL Classes項目添加到項目中並打開 O/R設計器後,空的設計圖面表示準備配置的空DataContext類。 DataContext類是LINQ to SQL類,充當SQL Server數據庫和映射到該數據庫的LINQ to SQL實體類之間的管道。此類包含連接字符串信息以及用於連接數據庫和操作數據庫中數據的方法。它配置有第一項提供的連接信息,該信息被拖動到設計圖面上。

What is the difference between the Take and Skip clauses?

Take和Skip子句之間有什麼區別?

The Take clause returns a specified number of elements. For example, you can use the Take clause to return two values from an array of numbers. The Skip clause skips the specified number of elements in the query and returns the rest. For example, you can use the Skip clause to skip the first four strings in an array of strings and return the remaining array of string.

Take子句返回指定數量的元素。例如,您可以使用Take子句從數字數組中返回兩個值。 Skip子句跳過查詢中指定數量的元素,並返回其餘元素。例如,您可以使用Skip子句跳過字符串數組中的前四個字符串,並返回其餘的字符串數組。

What is Object Relational Designer (O/R Designer)?

什麼是對象關係設計器(O/R設計器)?

The O/R Designer provides a visual design surface to create LINQ to SQL entity classes and associations (relationships) that are based on objects in a database.

O/R設計器提供了一個可視化的設計圖面,用於創建基於數據庫對象的LINQ to SQL實體類和關聯(關係)。

Which interface implements the standard query operators in LINQ?

哪個接口在LINQ中實現了標準查詢運算符?

The standard query operators implement the IEnumerable or the IQueryable interface in C# and the IEnumerable(Of T) or the IQueryable(Of T) interface in Visual Basic.

標準查詢運算符在C#中實現IEnumerable<T>IQueryable<T>接口,在Visual Basic中實現IEnumerable(Of T)IQueryable(Of T)接口。

What are standard query operators in LINQ?

LINQ中的標準查詢運算符是什麼?

The standard query operators in LINQ are the extension methods that form the LINQ pattern. These operators form an API that enables querying of any .NET array or collection. It operates on sequences and allows you to perform operations, such as determining if a value exists in the sequence and performing an aggregated function, such as a summation over a sequence.

LINQ中的標準查詢運算符是形成LINQ模式的擴展方法。這些運算符形成一個API,該API可以查詢任何.NET數組或集合。它對序列進行操作,並允許您執行操作,例如確定序列中是否存在值以及執行聚合函數,例如對序列求和。

On what parameter does the GroupBy clause group the data?

GroupBy子句將數據分組在哪個參數上?

The GroupBy clause groups the elements that share a common attribute.

GroupBy子句對共享公共屬性的元素進行分組。

Explain what are LINQ query expressions?

解釋什麼是LINQ查詢表達式?

Query expression is nothing but an LINQ query. It is a combination of query clauses that identifies the data sources for a query. It contains information for sorting, filtering, grouping or joining to apply to the source data. It determines what information should be retrieved from the data source.CV.
查詢表達式不過是LINQ查詢。它是查詢子句的組合,用於標識查詢的數據源。它包含用於排序,過濾,分組或聯接以應用於源數據的信息。它確定應從數據源中檢索哪些信息。

Explain what are compiled queries?

解釋什麼是編譯查詢?

In compiled LINQ queries, the plan is cached in a static class and static class is a global cache. Rather than preparing the query plan from scratch, LINQ prepares plan using stating class object.

在已編譯的LINQ查詢中,計劃被緩存在靜態類中,而靜態類是全局緩存。 LINQ並不是從頭開始準備查詢計劃,而是使用陳述類對象來準備計劃。

Explain how standard query operators useful in LINQ?

解釋標準查詢運算符在LINQ中如何有用?

Standard Query Operators useful in LINQ are

Get a total count of elements in the collection

Order the results of a collection

Grouping

Computing average

Joining two collections based on matching keys

Filter the results

在LINQ中有用的標準查詢運算符是

獲取集合中元素的總數

訂購收集結果

分組

計算平均值

根據匹配鍵連接兩個集合

篩選結果

Explain what is ‘LINQ to Objects’?

解釋什麼是“ LINQ to Objects”?

When LINQ queries any IEnumerable(Of T) collection or IEnumerable directly without the use of an intermediate LINQ provider or API such as LINQ to SQL or LINQ to XML is referred as ‘LINQ to Objects.’

當LINQ直接查詢任何IEnumerable(Of T)集合或IEnumerable而不使用中間LINQ提供程序或API(例如LINQ to SQL或LINQ to XML)時,稱爲“ LINQ to Objects”。

What is a LinqDataSource control?

什麼是LinqDataSource控件?

The LinqDataSource control enables you to use LINQ. in an ASP.NET Web page by setting the properties in the markup text. You can use the control retrieve or modify data. It is similar to the SqIDataSource and ObjectDataSource controls in the sense that it can be used to declaratively bind other ASP.NET controls on a page to a data source. The difference is that instead of binding directly to a database or to a generic class, the LinqDataSource control is designed to bind a LINQ enabled data model.

LinqDataSource控件使您可以使用LINQ。通過在標記文本中設置屬性,可以在ASP.NET網頁中顯示。您可以使用控件檢索或修改數據。從某種意義上說,它與SqIDataSourceObjectDataSource控件類似,可以用來聲明性地將頁面上的其他ASP.NET控件綁定到數據源。區別在於,LinqDataSource控件旨在直接綁定到啓用了LINQ的數據模型,而不是直接綁定到數據庫或泛型類。

Explain how you can differentiate between Conversion Operator ‘ToDictionary’ and ‘IEnumerable’ of LINQ?

說明如何區分LINQ的轉換運算符’ToDictionary’ 和 ‘IEnumerable’?

To solve the conversion type problems ‘IEnumerable’ and ‘ToDictionary’ conversion operator are used.
‘ToDictionary’ conversion operator is the instance of Dictionary (k, T). The ‘keySelector’ predicate recognizes the key of each item, while 'elementSelector, is used to extract each single item, if it is given.
Extension method on ‘IEnumerable’ is.AsEnumerable. AsEnumerable simply returns the source sequence as an object of type IEnumerable .

爲了解決轉換類型問題,使用了“ IEnumerable”和“ ToDictionary”轉換運算符。
“ ToDictionary”轉換運算符是Dictionary (k, T)的實例。 “ keySelector”謂詞可識別每個項的鍵,而“ elementSelector”則用於提取每個單個項(如果已給出)。
IEnumerable的擴展方法是AsEnumerableAsEnumerable只是將源序列作爲IEnumerable <T>類型的對象返回。

What are the different implementations of LINQ?

LINQ有哪些不同的實現?

The different implementations of LINQ are:

LINQ to SQL - Refers to a component of.NET Framework version 3.5 that provides a run-time infrastructure to manage relational data as objects.

LINQ to DataSet - Refers to a component that makes it easier and faster to query over data cached in a DataSet object.

LINQ to XML - Provides an in-memory XML programming interface.

LINQ to Objects - Refers to the use of LINQ queries with any IEnumerable or IEnumerable(T) collection directly, without the use of an intermediate LINQ provider or API, such as LINQ to SQL or LINQ to XML.

LINQ的不同實現是:

LINQ to SQL-指.NET Framework 3.5版的組件,該組件提供運行時基礎結構來將關係數據作爲對象進行管理。

LINQ to DataSet-指的是一個組件,該組件可以更輕鬆,更快速地查詢DataSet對象中緩存的數據。

LINQ to XML-提供內存中的XML編程接口。

LINQ to Objects-指直接將LINQ查詢與任何IEnumerableIEnumerable(T)集合一起使用,而不使用中間LINQ提供程序或API,例如LINQ to SQLLINQ to XML`。

Which command-line tool generates code and mapping for the LINQ to SQL component of .NET Framework?

哪個命令行工具爲.NET Framework的LINQ to SQL組件生成代碼和映射?

The SqlMetal.exe command-line tool generates code and map the LINQ to SQL component.
Name the control that exposes the LINQ features to Web developers through the ASP.NET data-source control architecture.
The LinqDataSource control exposes the LINQ features to Web developers through the ASP.NET data-source control architecture.

SqlMetal.exe命令行工具生成代碼並將LINQ映射到SQL組件。
通過ASP.NET數據源控件體系結構,爲向Web開發人員公開LINQ功能的控件命名。
LinqDataSource控件通過ASP.NET數據源控件體系結構向Web開發人員公開LINQ功能。

What is the difference between the Select clause and SelectMany() method in LINQ?

LINQ中的Select子句和SelectMany()方法有什麼區別?

Both the Select clause and SelectMany() method are used to produce a result value from a source of values. The difference lies in the result set. The Select clause is used to produce one result value for every source value. The result value is a collection that has the same number of elements from the query. In contrast, the SelectMany() method produces a single result that contains a concatenated collection from the query.

Select子句和SelectMany()方法均用於從值源生成結果值。區別在於結果集。 Select子句用於爲每個源值生成一個結果值。結果值是具有與查詢中相同數量的元素的集合。相比之下,SelectMany()方法將產生一個單個結果,其中包含來自查詢的串聯集合。

Which extension method do you need to run a parallel query in PLINQ?

您需要哪種擴展方法在PLINQ中運行並行查詢?

The AsParallel extension method is required to run a parallel query in PLINQ.

若要在PLINQ中運行並行查詢,需要使用AsParallel擴展方法。

What is the difference between the Select clause and SelectMany() method in LINQ?

LINQ中的Select子句和SelectMany()方法有什麼區別?

In both the Select clause and SelectMany() method a result value will be generated out of the source of values.

The difference between both of them is in the result set. The Select clause will generate one value for every source value.

The result value is a collection which is having the same number of elements from the query.

On the other side, theSelectMany() method generates a single result that has a concatenated from the query.

在Select子句和SelectMany()方法中,都會從值的源中生成結果值。

兩者之間的差異在於結果集中。 Select子句將爲每個源值生成一個值。

結果值是一個集合,該集合具有與查詢中相同數量的元素。

另一方面,SelectMany()方法生成一個具有從查詢中串聯的結果。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章