SQL Server Questions and Answers – LINQ – 2

This set of SQL Server online quiz 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

Answer: d
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

Answer:a
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

Answer: b
Explanation: A new data-access provider, EntityClient is created for LINQ to SQL for .net framework.

advertisement
advertisement

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

Answer: a
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

Answer: c
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

Answer: b
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)

advertisement
Enumerable<Product> beverages = FROM p IN db.Products
                     WHERE p.Category.CategoryName == "Beverages"
                     orderby p.ProductName
                     SELECT p;

b)

advertisement
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

Answer: b
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

Answer: a
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

Answer: c
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

Answer: b
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 for online quizzes, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.