This set of SQL Server Multiple Choice Questions & Answers (MCQs) focuses on “LINQ – 2”.
1. LINQ to SQL in SQL Server fully supports ____________
a) Transactions
b) Functions
c) Stored Procedures
d) All of the mentioned
View Answer
Explanation: LINQ provides an easy way to integrate data validation and business logic rules into your data model, and supports single table inheritance in the object model.
2. Point out the wrong statement.
a) LINQ to SQL is translated to SQL by way of Binary Trees
b) LINQ to SQL is translated to SQL calls and executed on the specified database while LINQ to Objects is executed in the local machine memory
c) LINQ to SQL is translated to SQL calls and executed on the specified database while LINQ to Objects is executed in the local machine memory
d) LINQ to SQL needs a Data Context object
View Answer
Explanation: LINQ to SQL is translated to SQL by way of Expression Trees,which allow them to be evaluated as a single unit and translated to the appropriate and optimal SQL statements.
3. LINQ to Entities applications requires __________ mapping provider.
a) DataClient
b) EntityClient
c) SqlClient
d) All of the mentioned
View Answer
Explanation: A new data-access provider, EntityClient is created for LINQ to SQL for .net framework.
4. The ______ pre-compiler translates embedded SQL into calls to the Oracle runtime library.
a) Pro*C
b) ORM
c) ApexSQL
d) None of the mentioned
View Answer
Explanation: Oracle Pro*C is a set of APIs supplied by Oracle to query, insert, update, or delete records in an Oracle database from C applications.
5. Point out the correct statement.
a) Compared to LINQ to Entities, LINQ to SQL has more limitations
b) MSL stands for Map Schema Language
c) If you want to work against a conceptual data model, use LINQ to Entities
d) Conceptual Data Model feature is present in LINQ to SQL
View Answer
Explanation: For direct mapping to the database from your programming languages, use LINQ to SQL.
6. DataContext object is constructed in LINQ to SQL using _____________
a) NorthwindDataContext db = new malloc NorthwindDataContext();
b) NorthwindDataContext db = new NorthwindDataContext();
c) NorthwindDataContext db = new NorthwindData();
d) None of the mentioned
View Answer
Explanation: To query a database using LINQ to SQL, we first need to construct a DataContext object.
7. Which of the following code will retrieve all products in the Beverages category sorted by product name?
a)
Enumerable<Product> beverages = FROM p IN db.Products WHERE p.Category.CategoryName == "Beverages" orderby p.ProductName SELECT p;
b)
IEnumerable<Product> beverages = FROM p IN db.Products WHERE p.Category.CategoryName == "Beverages" orderby p.ProductName SELECT p;
c)
IEnumerable<Product> beverages = FROM p IN db.Products WHERE p.Category.CategoryName = "Beverages" orderby p.ProductName SELECT p;
d) All of the mentioned
View Answer
Explanation: This is the LINQ query syntax to retrieve records from the database.
8. Which of the following sample code is used to retrieve single row at a time?
a)
public USER GetUser(string userName) { DBNameDataContext myDB = NEW DBNameDataContext(); USER USER = myDB.Users.Single(u, u.UserName=>userName); RETURN USER; } ?
b)
public USER GetUser(string userName) { DBNameDataContext myDB = NEW DBNameDataContext(); USER USER = myDB.Users.One(u, u.UserName=>userName); RETURN USER; } ?
c)
public USER GetUser(string userName) { DBNameDataContext myDB = NEW DBNameDataContext(); USER USER = myDB.Users.findOne(u, u.UserName=>userName); RETURN USER; } ?
d) All of the mentioned
View Answer
Explanation: LINQ provides much more flexibility of select single item/row from database table like ‘DBNameDataContext’.
9. Which of the following method is used to delete records in LINQ?
a) DeleteOn
b) Delete
c) DeleteOnSubmit
d) None of the mentioned
View Answer
Explanation: DeleteOnSubmit is used to delete rows from a table in LINQ to SQL conversion.
10. Which of the following code in LINQ performs functionality similar to joins in SQL?
a)
var categoryProducts = FROM c IN db.Categories SELECT NEW {c.CategoryName, productCount = products.Count()}; foreach (var cp IN categoryProducts) { Console.WriteLine("There are {0} products in category {1}", cp.CategoryName, cp.productCount); }
b)
var categoryProducts = FROM c IN db.Categories JOIN p IN db.Products ON c.CategoryID equals p.CategoryID INTO products SELECT NEW {c.CategoryName, productCount = products.Count()}; foreach (var cp IN categoryProducts) { Console.WriteLine("There are {0} products in category {1}", cp.CategoryName, cp.productCount); }
c)
var categoryProducts = FROM c IN db.Categories JOIN p IN db.Products ON c.CategoryID equals p.CategoryID INTO products foreach (var cp IN categoryProducts) { Console.WriteLine("There are {0} products in category {1}", cp.CategoryName, cp.productCount); }
d) None of the mentioned
View Answer
Explanation: LINQ query is preferred When there is no foreign key association between two tables.
Sanfoundry Global Education & Learning Series – SQL Server.
To practice all areas of SQL Server, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Programming Internship
- Practice Programming MCQs
- Check Information Technology Books
- Check SQL Server Books