1⟩ What is the extension of the file, when LINQ to SQL is used?
The extension of the file is .dbml
“LINQ Interview Questions and Answers will guide us now that Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages. LINQ defines a set of method names called standard query operators, or standard sequence operators, along with translation rules from so-called query expressions to expressions using these method names, so learn more abut LINQ with the help of this LINQ Interview Questions with Answers guide”
The extension of the file is .dbml
Because, it is not serializable
There are couple of advantage of LINQ over stored procedures.
1. Debugging - It is really very hard to debug the Stored procedure but as LINQ is part of .NET, you can use visual studio's debugger to debug the queries.
2. Deployment - With stored procedures, we need to provide an additional script for stored procedures but with LINQ everything gets complied into single DLL hence deployment becomes easy.
3. Type Safety - LINQ is type safe, so queries errors are type checked at compile time. It is really good to encounter an error when compiling rather than runtime exception!
It stands for Language Integrated Query. LINQ is collection of standard query operators that provides the query facilities into .NET framework language like C# , VB.NET.
Standard Query Operators are implemented as extension methods in .NET Framework. These Standard Query Operators can be used to work with any collection of objects that implements the IEnumerable interface. A class that inherits from the IEnumerable<t> interface must provide an enumerator for iterating over a collection of a specific type. All arrays implement IEnumerable<t>. Also, most of the generic collection classes implement IEnumerable<t> interface.
(C#) - Deferred Loading is a property of Linq to sql, by default it is set true,
Example – Let’s have two tables -
Blogs Table (BlogID ,Blog Name,owner) and Post table ( PostID, BlogID, Title, Body)
To find Name and No’s of posts in each blog:
BlogDataContext ctx = new BlogDataContext( );
var query = from b in ctx.Blogs select b;
foreach (Blog b in query)
{
Console.WriteLine("{0} has {1} posts", b.BlogName,
b.Posts.Count);
}
Output of queries Produce Blog name with no’s of post, But For each Blog Looping will be occurs (in case long list of blogs) that’s reduces Overall Performance that’s called the Deferred loading.
The extension of the file is .dbml
Because datareader is not serializable.
System.XML.XLinq.dll contains classes to provide functionality to use LINQ with XML.
1. Standard Query Operators
2. Language Extensions
3. LINQ Providers
Benefits and Advantages of LINQ are:
1. Makes it easier to transform data into objects.
2. A common syntax for all data.
3. Strongly typed code.
4. Provider integration.
5. Reduction in work.
6. Performance in the general case doesn't become an issue.
7. Built-in security.
8. LINQ is declarative.
There are couple of advantage of LINQ over stored procedures.
1. Debugging - It is really very hard to debug the Stored procedure but as LINQ is part of .NET, you can use visual studio's debugger to debug the queries.
2. Deployment - With stored procedures, we need to provide an additional script for stored procedures but with LINQ everything gets complied into single DLL hence deployment becomes easy.
3. Type Safety - LINQ is type safe, so queries errors are type checked at compile time. It is really good to encounter an error when compiling rather than runtime exception!
4. PreCompiled - Stored Procedures are precompiled, and LINQ queries need to compile before execution. So stored procedures are fast in performance.
The reason is, LINQ is used with C# or other programming languages, which requires all the variables to be declared first. From clause of LINQ query just defines the range or conditions to select records. So that’s why from clause must appear before Select in LINQ.
its .dbml
A Lambda expression is nothing but an Anonymous Function, can contain expressions and statements. Lambda expressions can be used mostly to create delegates or expression tree types. Lambda expression uses lambda operator => and read as 'goes to' operator.
Left side of this operator specifies the input parameters and contains the expression or statement block at the right side.
Example: myExp = myExp/10;
Now, let see how we can assign the above to a delegate and create an expression tree:
delegate int myDel(int intMyNum);
static void Main(string[] args)
{
//assign lambda expression to a delegate:
myDel myDelegate = myExp => myExp / 10;
int intRes = myDelegate(110);
Console.WriteLine("Output {0}", intRes);
Console.ReadLine();
//Create an expression tree type
//This needs System.Linq.Expressions
Expression<myDel> myExpDel = myExp => myExp /10;
}
No te:
The => operator has the same precedence as assignment (=) and is right-associative.
Lambdas are used in method-based LINQ queries as arguments to standard query operator methods such as Where.
System.Data.DLinq.dll provides functionality to work with LINQ to SQL.
System.Query.dll assembly represents the core LINQ API.
1. System.Linq.Enumerable
2. System.Linq.Queryable
3. None of these
The main aim of using LINQ to Dataset is to run strongly typed queries on Dataset.
Suppose we want to combine the results from two Datasets, or we want to take a distinct value from the Dataset, then it is advisable to use LINQ.
Normally you can use the SQL queries to run on the database to populate the Dataset, but you are not able to use SQL query on a Dataset to retrieve a particular values. To get this you need to use ADO.NET functionalities. But, in case of LINQ, it provides more dignified way of querying the Dataset and provides some new features as compared to ADO.NET.
Both are the classes defined by System.Xml.Linq namespace
XElement class represents an XML fragment
XDocument class represents an entire XML document with all associated meta-data.
example:
XDocument d = new XDocument(
new XComment("hello"),
new XElement("book",
new XElement("bookname", "ASP.NET"),
new XElement("authorname", "techmedia"),
)
);