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()方法生成一个具有从查询中串联的结果。

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