We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, August 14, 2015

Interview questions and answers of ADO.NET,LINQ&ENTITY FRAMEWORK

1)what is ADO.NET?
 ADO.NET is an object-oriented set of libraries that allows you to interact with data sources. Commonly, the data source is a database, but it could also be a text file, an Excel spreadsheet, or an XML file.in other words, we will look at ADO.NET as a way to interact with a database.

2)what are data providers present in ado.net
  • ODBC Data Provider
  • OleDb Data Provider
  • Oracle Data Provider
  • SQL Data Provider
  • Borland Data Provider.
3)what are ado.net objects?

  • Sqlconnection object
  • Sqlconnection object
  • Sqlcommand object
  • DataReader object
  • Dataset object
  • DataAdapter object


 4)what are constructors of connection class?
  • connection();
  • connection(string connectionstring);
5)what are  Members of Connection class?
  • Open(): a method that opens a connection with the data source.
  • Close(): a method that closes the connection that is open.
  • State: an enumerated property that is used to get the status of the connection.
  • ConnectionString: a property is used to get or set a connection string that is associated with the connection object.
6)what is connection pooling?
        Connection pooling is the ability to re-use your connection to the Database. This means if you enable Connection pooling in the connection object, actually you enable the re-use of the connection to more than one user.

7)what is ado and What is it Features?
  • ADO is also for accessing data from data sources but it has limited functionalities
  • ADO is base on COM : Component Object Modelling based.
  • ADO stores data in binary format
  • Data is provided by RECORDSET
  • ADO is connection-oriented means it requires a continuous active connection.
  • In ADO, You can create only Client-side cursor
8)how many architectures are there in ado.net
  • Connected architecture
  • Disconnected architecture
9)what is connected architecture and about this architecture?

  • It means, we require continuous a connection from database and we have to close the connection manually
  • Only forwarding navigation of records.
  • Read-only data
  • Updation of records not allowed
10) what is the meaning of min pool size in ado.net?
If MinPoolSize is either not specified in the connection string or is specified as zero, the connections in the pool will be closed after a period of inactivity. However, if the specified MinPoolSize is greater than zero, the connection pool is not destroyed until the AppDomain is unloaded and the process ends. Maintenance of inactive or empty pools involves minimal system overhead.

11) what is the max pool size in the connection string.
100 is the maximum number of connections allowed in the pool. & if we want to increase we can increase.

12) what is SSPI?
Security Support Provider Interface, it allows an application to use any of the security packages on a system without changing the interface to use security services.

14)what is the command object?
 The Command Object in ADO.NET executes SQL statements and Stored Procedures against the data source specified in the C# Connection Object. The Command Object requires an instance of a C# Connection Object for executing the SQL statements.

15)properties of command class?

  • Command text: which contains a String value that represents the command that will be executed against the  Data Source
  • Command type: Command Type property is set to StoredProcedure, the Command Text property should be set to the name of the stored procedure.
16) Difference Between connection() and connection(string connection string)?

  • SqlConnection (): Initializes a new instance of the SqlConnection class.
  • SqlConnection (String connection String):  Initializes a new instance of the SqlConnection class when given a string that contains the connection string.
17)methods of command class?
  •  Execute Reader()                ->        DataReader
  •  Execute Scalar()                  ->        object
  •  ExecuteNonQuery()            ->        int
18)which method is to navigate from one table to other?
NextResult() method on data reader object to navigate from the current table to the next table.
E.g.: dr.NextResult();

19)what is the function of ExecuteReader?
 Use ExecuteReader() method when we want to execute a Select Statement that returns data as rows and columns. The method returns an object of class DataReader which holds data that is retrieved from data sources in the form of rows and columns.

20)what is function of ExecuteScalar()?
 Use ExecuteScalar() method when we want to execute a Select a Statement that returns a single value result. The method returns the result of the query in the form of an object.

 Disconnected Architecture

1. What is Disconnected architecture?
we don’t require a continuous connection with the data source for accessing the data from it, we require the connection only for loading the data from the data source and here DataSet class is used for holding the data on client machines.

2. Explain about dataset objects?
Dataset is a collection of tables where each table is represented as a DataTable class and identified by the index position. It is a class present under the “System.Data” namespace design for holding and managing data on client machines apart from a DataReader.

3. Explain the features of a dataset?
  • It is also capable of holding multiple tables.
  • It is a designed disconnected architecture that doesn't require a permanent connection with a Data Source for holding data.
  • It provides scrollable navigation to data, that allows us to move in any direction.
In other words, either top to bottom or bottom to top.
  • It is updatable, in other words changes can be performed to data present in it and also send changes back to the DB.
4. Explain about working with the dataset?
This class is responsible for the loading of data into a DataReader from a DataSource and is a command.
In the same way, the DataAdapter class is used for communication between a DataSource and DataSet.
Simply
  • DataReader< - Command ->DataSource.
  • DataSet<->DataAdapter<->DataSource
5.what are the objects in Dataset?
  •  DataTable object
  •  DataRow objects
  • DataColumn objects
  • DefaultView object
6. Explain about DataAdapter object?
These are objects that connect one or more Command objects to a Dataset object. They
provide logic that would get data from the data store and populates the tables in the
DataSet, or pushes the changes in the DataSet back into the data store.
1.AnOleDbDataAdapter object is used with an OLE-DB provider
2.ASqlDataAdapter object uses Tabular Data Services with MS SQL Server

7.what object DataAdapter will use internally too with a database?
Command object.
DataAdapter is internally a collection of the following 4 methods:
  • Select Command.
  • Insert Command.
  • Update Command.
  • Delete Command.
8.what are the methods of data adapter?
  • Fill
  • FillSchema
  • Update
There are three most commonly used methods of DataAdapter:-
Fill:- Executes the SelectCommand to fill the DataSet object with data from the data source. It an also, be used to update (refresh) an existing table in a DataSetwithchangesmade to the data in the original data source if there is a primary key in the table in the dataset.

FillSchema:- Uses the SelectCommand to extract just the schema for a table from the data source, and creates an empty table in the DataSet object with all the corresponding constraints.

Update:- Calls the respective InsertCommand, UpdateCommand, or DeleteCommandforeach inserted, updated, or deleted row in the DataSet so as to update the original data source with the changes made to the content of the DataSet. This is a little like theUpdateBatch method provided by the ADO Recordset object, but in the DataSet it can be used to update more than one table.

9.what is dataset object?
The DataSet provides the basis for disconnected storage and manipulation of relational
data. We fill it from a data store, work with it while disconnected from that data store,
then reconnect and flush changes back to the data store if required.

10.what are the methods used in dataset object to use XML?
XML is one of the most important leaps between classic ADO andADO.NET.
1.ReadXML:Read’s a XML document in to Dataset.
2.GetXML: This is a function that returns the string containing the XML document.
3.WriteXML: This writes an XML data to disk.

11.how can we save all data from dataset?
Dataset has “AcceptChanges” a method which commits all the changes since last time
“Acceptchanges” has been executed.

12. How can we check that some changes have been made to the dataset since it was loaded?

  • GetChanges: Returns a dataset which is changed since it was loaded or since Acceptchangeswasexecuted.
  • HasChanges: This property indicates that has any changes been made since the dataset was loaded or accept changes method was executed.
13. What is the difference between Dataset.clone and Dataset.copy ?
Clone: – It only copies the structure does not copy data.
Copy: – Copies both structure and data.

14. Can you explain the difference between an ADO.NETDataset and an ADO Recordset?
There two main basic differences between recordset and dataset:-
With dataset, you an retrieve data from two databases like oracle and SQL
server and merge them in one dataset, with record set this is not possible
2. All representation of Dataset is using XML while the recordset uses COM.

15. How can we add relations between two data table objects?
By using DataRelation object.

16.what are the DataAdapter constructors?

  • DataAdapter(string select command, Connection con)
  • DataAdapter(Command cmd)
17.What is Serialization and De-Serialization in .Net? How can we serialize the DataSet object?
Serialization is the process of converting an object into a stream of bytes that can be stored and transmitted over a network. We can store this data into a file, database or Cache object. De-Serialization is the reverse process of serialization. By using de-serialization we can get the original object that is previously serialized. The following are the important namespaces for Serialization in .NET.
- System.Runtime.Serialization namespace.
- System.Runtime.Serialization.Formatters.Binary
- System.Xml.Serialization
The main advantage of serialization is that we can transmit data across the network in a cross-platform environment and we can save in a persistent or non-persistent storage medium. Serialization can be the following types:
a.     Binary Serialization
b.     SOAP Serialization
c.      XML Serialization
d.     Custom Serialization

18.what is the difference between the typed dataset and the untyped dataset?
Typed Dataset use explicit names and datatypes for their members.
Untyped Datasets use the table and column collections for their members.
Typed Dataset has a schema and the untyped dataset does not have one. It should be noted that Typed DataSet supports the visual studio.

19. How can you sort a dataset?
DataView has a sort method.

20.what is the use of a command builder object?
Thacommanbuilder class is used to automatically update a database according to the changes made in a dataset. Whenever  data inside a row changes the object of command builder class automatically generates SQL statements and uses the select-command property to commit the changes made in a dataset.

21.how to identify the updated rows in a dataset.
If the RowStatepropertyof the DataRow is” Modified” then that  DataRow can be treated  as updated.

22. What is the difference between DataSet and DataReader?
The following are the main difference between DataSet and DataReader.

DataSet
  • Consumer Object
  • Provides Disconnected mode
  • Forward and backward scanning of data
  • Slower access to data
  • Can store multiple tables simultaneously
  • Read/Write access
DataReader
  • Provider Object
  • Provides Connected mode
  • Forward-only cursor
  • Faster access to data
  • Supports a single table based on a single SQL query
  • Read Only access
23.can we connect two data adapters to the same data source using single connection at the same time?
Yes, we can connect two data adapters to the same data source using single connection at the same time. There is a technology in ado.net 2.0 called MARS using Mars in connection string we can do it.

24.can we connect two data readers to the same data source using single connection at the same time?
Yes, it is possible but one main thing you have to close the first DataReader before using the second one. Then only it is possible.

25. How can we add/remove rows in the DataTable object of a dataset ?
Datatable provides the NewRow method to add a new row to DataTable. DataTablehasDataRowCollection object which has all rows in a DataTable object. Following are the methods provided by DataRowCollectionobject :-
1. Add: Adds a new row in Data Table
2. Remove: It removes a Data Row object from Data Table
3. RemoveAt: It removes a Data Row object from Data Table depending on the index position of the DataTable.

26. What is basic use of Data View?
DataView represents a complete table or can be a small section of rows depending on some criteria. It is best used for sorting and finding data within the data table.

27.what are the methods of DataView?
Dataview has the following method’s:-
1. Find: It takes an array of values and returns the index of the row.
2.FindRow: This also takes array of values but returns a collection of DataRow.
If we want to manipulate data of DataTable object create DataView (Using the default view we can create DataView object) of the DataTable object and use the following functionalities:-
AddNew:Adds a new row to the DataView object.
Delete: Deletes the specified row from the DataView object.

LINQ
Q1.   What is LINQ?
Ans: - LINQ stands for "Language Integrated Query" and pronounced as "LINK".   It enables you to query the data from the various data sources like SQL databases, XML documents, ADO.NET Datasets.

Q2.  Why LINQ?
Ans: - LINQ has full type checking at compile-time and IntelliSense support in Visual Studio since it used the .NET framework languages like C# and VB.NET. This powerful feature helps you to avoid run-time error

Q3. Which Namespace is necessary to use LINQ?
Ans: - System. Linq a namespace is necessary for writing LINQ queries and to implement it.

Q4. What are the different Flavors of LINQ?
  • LINQ to Object
  • LINQ to ADO.NET
  • LINQ to SQL (DLINQ)
  • LINQ to DataSet
  • LINQ to Entities
  • LINQ to XML (XLINQ)
  • Parallel LINQ
Q5.  What are the Advantages of using  LINQ on DataSet?
Ans: - LINQ to DataSet is useful to run strongly typed queries on multiple datasets. An SQL query is able to populate the dataset from the database but not able to retrieve a particular value from the dataset. LINQ is the best way to do further data manipulation operations (like searching, filtering, sorting) on Dataset in an efficient way.

Q6. What is the extension of File, when LINQ to SQL is used?
Ans: - The extension of the file is .dbml. (Database Markup Language).

Q7. What is DataContextClass?
Ans: - Data context class is a LINQ to SQL class that acts as a medium between a SQL Server database and LINQ to SQL entities classes mapped to that database.

Q8. What is the Role Of DataContextClass?
Ans: - Contains the connection string information, methods to connect to the database and manipulating the data in the database.
- With data context, we can perform select, insert, update and delete operations over the data in the database.
- It contains several methods that send updated data from LINQ to SQL entity classes to the database.

Q9. What are the basic steps  to executes the LINQ Queries?
Ans : - 

  •  Obtain DataSource (The DataSource can be either an SQL Database or an XML file)
  •  Create a Query
  • Executes a Query
Q10. In which statement the LINQ query is executed?
Ans: - A LINQ query is executed in the “For Each” statement in Visual Basic and in the “foreach” statement in C#.

Q10. What is PLINQ?
Ans:-  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.

Q11. What is Object-Relational Designer (O/R Designer)?
Ans:- The 0/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.

Q12. Which Extention method do you need  to run a Parallel query in LINQ?
Ans: - The AsParallel an extension method is required to run a parallel query in PLINQ.

Q13. Which Assembly represents the core LINQ API?
Ans : - System.Query.dll   assembly represents the core LINQ API

Q14. What is the function of the DISTINCT clause in a LINQ query?
Ans: - The DISTINCT clause returns the result set without the duplicate values.

Q15. Define what is Where clause and Let clause?
Ans: - 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 value

 Entity Framework

1. What is the .NET Entity Framework?
  The Microsoft ADO.NET Entity Framework is an Object/Relational Mapping (ORM) framework that enables developers to work with relational data as domain-specific objects, eliminating the need for most of the data   access plumbing code that developers usually need to write.

2. What is EDM (Entity Data Model)?
  EDM consists of three main parts- i) Conceptual model ii) Mapping iii)Storage model.

3. What is the Storage Model?
  Storage model is the database design model which consists of tables, views, stored procedures, and their relationships and keys.

4. What is the minimum requirement for Entity Framework applications to run?
  Entity Framework applications can run on any computer on which the .NET Framework starting with version 3.5 included.

5. What is MSL?
 Mapping specification language (MSL) is an An XML-based language that describes the mapping between the conceptual model and storage model of an Entity Framework application.

6. What is CSDL?
 Conceptual schema definition language (CSDL) is an XML-based language that describes the entities, relationships, and functions that make up a conceptual model of a data-driven application. This conceptual  model can be used by the Entity Framework or WCF Data Services.

7. What is SSDL?
 Store schema definition language (SSDL) is An XML-based language that describes the storage model of an Entity  Framework application.

8. What is Mapping in Entity Framework?
 Mapping contains information about the conceptual model which is mapped to the storage model.

9. What is EntityContainer?
EntityContainer is a Wrapper for EntitySet and AssociationSets. It is a critical entry point for querying the model.

10. What is EntitySet?
EntitySet is a container for EntityType. It is a set of the same entity type. It is like db table.

11. What is EntityType?
EntityType is a datatype in the model.
 Each EntityType for the conceptual model is described in XML.

12. What is the AssociationSet?
AssociationSet defines the relation between   each EntitySet

13. What is ObjectSet?
  Each EntitySet in context class is a type of   ObjectSet<> that wraps the entity.

 14. What is the Entity Graph?
 One Entity has a relation with other entities is known as the entity graph.
 Likewise, the Employee entity graph includes many other entities like Employee Address, Employee code, etc.

15. What are the advantages of Entity Framework:
 i) Database performance is improved. Database operations like select, insert, update, delete will work faster as we have not to execute in the query browser again and again.
ii) Entity Framework performing basic CRUD (Create, Read, Update, Delete) operations. So most of the time you don't have to write any SQL yourself. When you make any changes to the object, the ORM will usually detect this, and mark the object as 'modified'.
iii)Entity Framework works on databases other than Microsoft SQL Server, like Oracle, MySQL, etc. While Linq is limited to MS SQL Server.
iv)Ability to have inheritance relationships between entities.

16. What is a .edmx file?
 Visual Studio saves the entire Entity Data Model configurations in a file with a .edmx   extension. This file has an XML format. The .edmx file mainly has three sections namely the storage schema, conceptual schema, and the mappings.

17. Does Entity Framework support CRUD operations?
  Yes.
  CRUD included (Create, Read, Update, Delete), these are supported by Entity Framework.

18. What is Code First Approach?
 Entity Framework supported the development of applications using Schema first and Model First approach.
 In Code First approach, we are creating the code first and the Entity Framework will generate the corresponding Database according to code.

19. What is the Model First Approach?
 In the Model First approach, you create Entities, relationships, and inheritance hierarchies directly on the design surface of EDMX. So in Model First approach, when you add ADO.NET Entity Data Model, you should select ‘Empty Model’ instead of ‘Generate from database’.   
     
20. Does Entity Framework support LINQ?
Yes.
 The Entity Framework includes LINQ to Entities which exposes many of the same features as LINQ to SQL over your conceptual application data model.

21. What is Connected Scenario?
 The connected scenario is when an entity is retrieved from the database and modified in the same context.

22. What is Disconnected Scenario?
 The disconnected scenario is when an entity is retrieved from the database and modified in a different context. The disconnected scenario is complex because context doesn't know anything about a modified entity so you have to tell ObjectContext that what has changed in entity.


No comments: