Professional Documents
Culture Documents
5. Explain how Configuration works in ASP.NET Core and reading values from the
appsettings.json file.
ASP.NET Core config lives in key-value pairs across sources like files
(appsettings.json) and environment. Providers like JSON or environment vars read
these pairs and build a unified view. Access values by key using IConfiguration to
control app behavior without hardcoding.
Middleware: Global error handling with specific responses, logging, and custom
error pages.
Try/Catch: Localized error handling for specific scenarios and resource cleanup.
Exception Filters: Intercept and handle exceptions before reaching the middleware.
Descriptive Errors: Throw specific exceptions with clear messages for better
debugging.
Logging: Capture all exceptions for analysis and later troubleshooting.
10. How can ASP.NET Core APIs be used and accessed from a class library project?
Accessing ASP.NET Core APIs from a class library involves two key steps:
Target the ASP.NET Core Shared Framework: This ensures your library shares the same
base framework as an ASP.NET Core application, allowing seamless API usage.
Reference relevant NuGet packages: For specific ASP.NET Core functionalities,
install the corresponding NuGet packages within your class library project. This
grants access to specific API components you need.
C#
---
Unmanaged Code - Unmanaged code is any code developed outside the .NET framework.
Unmanaged applications are not executed by CLR. Some languages like C++ can write
unmanaged applications such as an application for accessing the low-level functions
of the operating system. Some examples of unmanaged code include background
compatibility with the code of VB, ASP, and COM.
Tasks are easier to use and manage than threads, and they can also be used to
provide more efficient resource utilization. Threads on the other hand, provide a
lower level of abstraction and are used to execute code directly in the processo
Following are the differences between Task and Thread in C#:
The main difference between ref and out keywords in C# is that ref requires that
the variable be initialized before being passed to the method whereas out keyword
doesn’t require the variable to be initialized before being passed to the method.
You can implement encapsulation by using access specifiers that define the scope
and visibility of a class member. Some access specifiers are as follows:
Public access specifier: It allows a class to expose its member functions and
variables to other objects and functions. It allows access to any public member
from outside the class.
Private access specifier: It allows a class to hide its member functions and
variables from other objects and functions. It allows only functions of the same
class to access its private members.
Protected access specifier: It allows a child class to access its base class's
member function and variables, thus helping in inheritance implementation.
Generics promotes the usage of parameterized types. You can also create collection
classes using generic. System.Collections.The generic namespace is used instead of
classes to create a generic collection.
Constructor dependency
Property dependency
Method dependency
The term polymorphism means "many shapes." It occurs when there are many classes
related to each other by inheritance.
For instance, at runtime, derived class objects may be treated as base class
objects in places like collections/ method parameters/ arrays. In such
polymorphism, declared and runtime types of objects are different. Thus,
polymorphism allows a class to have multiple implementations with the same name.
The lock statement acquires the mutual-exclusion lock for a given object, executes
a statement block, and then releases the lock. While a lock is held, the thread
that holds the lock can again acquire and release the lock. Any other thread is
blocked from acquiring the lock and waits until the lock is released.
A lock typically prevents more than one entity from accessing a shared resource.
Each object in the C# language has an associated lock, also referred to as a
monitor, which a thread obtains by using a synchronized method or block of code.
Both the lock statement and the Monitor class provide similar functionality by
ensuring exclusive access to shared resources. However, the Monitor class offers
more flexibility, allowing you to use other methods like Monitor. Wait and Monitor.
Pulse for more advanced synchronization scenarios.
Angular
--------
1. What is data binding? Which type of data binding does Angular deploy?
Data binding is a phenomenon that allows any internet user to manipulate Web page
elements using a Web browser. It uses dynamic HTML and does not require complex
scripting or programming. We use data binding in web pages that contain interactive
components such as forms, calculators, tutorials, and games. Incremental display of
a webpage makes data binding convenient when pages have an enormous amount of data.
Angular uses the two-way binding. Any changes made to the user interface are
reflected in the corresponding model state. Conversely, any changes in the model
state are reflected in the UI state. This allows the framework to connect the DOM
to the Model data via the controller. However, this approach affects performance
since every change in the DOM has to be tracked.
Single-page applications are web applications that load once with new features just
being mere additions to the user interface. It does not load new HTML pages to
display the new page's content, instead generated dynamically. This is made
possible through JavaScript's ability to manipulate the DOM elements on the
existing page itself. A SPA approach is faster, thus providing a seamless user
experience.
Class Decorators
Property Decorators
Method Decorators
Parameter Decorators
9. What is an ngModule?
NgModules are containers that reserve a block of code to an application domain or a
workflow. @NgModule takes a metadata object that generally describes the way to
compile the template of a component and to generate an injector at runtime. In
addition, it identifies the module's components, directives, and pipes, making some
of them public, through the export property so that external components can use
them.
{{ data }}
For example,
The template here is deleteHero. The method is called when the user clicks on the
button.
Promises - They emit a single value at a time. They execute immediately after
creation and are not cancellable. They are Push errors to the child promises.
Observables - They are only executed when subscribed to them using the subscribe()
method. They emit multiple values over a period of time. They help perform
operations like forEach, filter, and retry, among others. They deliver errors to
the subscribers. When the unsubscribe() method is called, the listener stops
receiving further values.
constructor() { }
ngOnInit(): void {
//....
<ul>
</ul>
“Let item” creates a local variable that will be available in the template
“Of items” indicates that we are iterating over the items iterable.
The * before ngFor creates a parent template.
In Angular, every component has a lifecycle. Angular creates and renders these
components and also destroys them before removing them from the DOM. This is
achieved with the help of lifecycle hooks. Here's the list of them -
Lazy loading dynamically loads the feature modules when there's a demand. This
makes the application faster. It is used for bigger applications where all the
modules are not required at the start of the application.
There are two ways to embed the bootstrap library into your application.
Angular Bootstrap via CDN - Bootstrap CDN is a public Content Delivery Network. It
enables you to load the CSS and JavaScript files remotely from its servers.
Angular Bootstrap via NPM - Another way to add Bootstrap to your Angular project is
to install it into your project folder by using NPM (Node Package Manager).
npm install bootstrap
This will create a new service file called my-data-service.ts in the src/app
folder.
Inject the service into any component that needs to share data:
To share data between components, simply use the setData() and getData() methods:
this.myDataService.setData('some data');
SQL:
--------
Syntax:
1
STUFF(String1, Position, Length, String2)
Here, String1 is the one that will be overwritten. The position indicates the
starting location for overwriting the string. Length is the length of the
substitute string, and String2 is the string that will overwrite String1.
Example:
1
select stuff(‘SQL Tutorial’,1,3,’Python’)
This will change ‘SQL Tutorial’ to ‘Python Tutorial’
Output:
1
Python Tutorial
Syntax:
1
2
3
4
5
6
7
CREATE TABLE #table_name();
The below query will create a temporary table:
create table #book(b_id int, b_cost int)
Now, we will insert the records.
insert into #book values(1,100)
insert into #book values(2,232)
select * from #book
3. What is a database cursor? How to use a database cursor?
A database cursor is a control that allows you to navigate around a table’s rows or
documents. It can be referred to as a pointer for a row in a set of rows. Cursors
are extremely useful for database traversal operations such as extraction,
insertion, and elimination.
After any variable declaration, DECLARE a cursor. A SELECT statement must always be
aligned with the cursor declaration.
To initialize the result set, OPEN statements must be called before fetching the
rows from the result table.
To grab and switch to the next row in the result set, use the FETCH statement.
To deactivate the cursor, use the CLOSE expression.
Finally, use the DEALLOCATE clause to uninstall the cursor description and clear
all the resources associated with it.
5. What are some common clauses used with SELECT queries in SQL?
There are many SELECT statement clauses in SQL. Some of the most commonly used
clauses with SELECT queries are as follows:
FROM
The FROM clause defines the tables and views from which data can be interpreted.
The tables and views listed must exist at the time the question is given.
WHERE
The WHERE clause defines the parameters that are used to limit the contents of the
results table. You can test for basic relationships or for relationships between a
column and a series of columns using subselects.
GROUP BY
The GROUP BY clause is commonly used for aggregate functions to produce a single
outcome row for each set of unique values in a set of columns or expressions.
ORDER BY
The ORDER BY clause helps in choosing the columns on which the table’s result
should be sorted.
HAVING
The HAVING clause filters the results of the GROUP BY clause by using an aggregate
function.
6. How can you copy data from one table to another table?
We have to copy this data into another table. For this purpose, we can use the
INSERT INTO SELECT operator. Before we go ahead and do that, we will have to create
another table that will have the same structure as the above-given table.
Syntax:
On the other hand, the IN operator serves as a condition operator utilized for
searching values within a predetermined range. When multiple values are available
for selection, the IN operator is utilized.
Entity Framework
------------------
1. What are the main components of Entity Framework Architecture?
Entity Framework Architecture consists of the following components:
Entity Data Model (EDM): EDMs abstract logical or relational schema and expose
conceptual schema of data with a three-layered model, i.e., Conceptual (C-Space),
Mapping (C-S Space), and Storage (S - Space).
LINQ to Entities (L2E): L2E is basically a query language generally used to write
queries against the object model. The entities defined in the conceptual model are
returned by L2E.
Entity SQL (E-SQL): Similar to L2E, E-SQL is another query language (for EF6 only).
The developer must however learn it separately since it is more difficult than L2E.
Internally, E-SQL queries are translated or converted to data store-dependent SQL
queries. EF is used for converting E-SQL queries to their respective datastore
queries, such as T-SQL.
Entity Client Data Provider: This layer's main task is to convert E-SQL or L2E
queries into SQL queries that the database understands. In turn, the ADO.Net data
provider sends and retrieves data from the database.
Net Data Provider: It uses standard ADO.NET to enable interaction with the
database.
Storage Model: It is also referred to as the Store Space Definition Language Layer
(S-Space). Schematically, it represents the storage area in the backend. Therefore,
the storage model is also known as a database design model that is composed of
tables, keys, stored procedures, views, and related relationships.
EDMX files represent conceptual models, storage models, and their mappings. This
file contains all the mapping information between SQL tables and objects. In
addition, it also includes essential information required for rendering models
graphically with ADO.NET Entity Data Designer. Furthermore, it is divided into
three divisions, CSDL, MSL, and SSDL.
Code First Approach: The Code First approach primarily uses classes to create the
model and its relations, which are then used to create a database. This way,
developers can work in an object-oriented manner without considering the database
structure. By following this model, developers first write POCO classes and then
use these classes to create the database. Code First is the method used by most
developers using Domain-Driven Design (DDD).
Model First Approach: In contrast, the Model First approach uses ORM to build model
classes and their relationships. Following the successful creation of the model
classes and relationships, the physical database is created using these models.
9. What do you mean by the term navigation property in the entity framework?
A foreign key relationship in the database is represented by the navigation
property supported by the Entity Framework. It is possible to specify relationships
between entities in a database using this property type. Relationships are defined
in a way as to remain coherent in object-oriented code.
Added: It is a state in which an entity exists within the context but does not
exist within the database. When the user invokes the SaveChanges method, DbContext
usually generates an INSERT SQL query to insert the data into the database. Upon
successful completion of the SaveChanges method, the entity's state changes to
unchanged.
Deleted: This state indicates that the entity is marked for deletion has not been
removed from the database. Also, it indicates the existence of the entity in the
database. When the user invokes the SaveChanges method, DbContext usually generates
a DELETE SQL query to delete or remove the entity from the database. Upon
successful completion of the delete operation, DbContext removes the entity.
Modified: When the entity is modified, its state becomes Modified. Also, it
indicates the existence of the entity in the database. When the user invokes the
SaveChanges method, DbContext usually generates an UPDATE SQL query to update the
entity from the database. Upon successful completion of the SaveChanges method, the
entity's state changes to unchanged.
Unchanged: Since the context retrieved the entity's property values from the
database, the values have not changed. This entity is ignored by SaveChanges.
Detached: This state indicates that the entity is not tracked by the DbContext. If
an entity was created or retrieved outside the domain of the current instance of
DbContext, then its entity state will be Detached.
14. Explain the role of Pluralize and Singularize in the entity framework.
Objects in Entity Framework are primarily assigned names using Pluralize and
Singularize. This feature is available when adding a .edmx file. Entity Framework
automatically assigns the Singular or Plural coding conventions when using this
feature. In convention names, an additional 's' is added if there is more than one
record in the object.
Dapper: A simple micro ORM, Dapper is considered a powerful system used for data
access in the .NET world. As a means to address and open-source their issues, the
Stack Overflow team created Dapper. Adding this NuGet library to your .NET project
allows you to perform database operations. In terms of speed, it is the king of
Micro ORMs and is almost as fast as using raw ADO.NET data readers.
Entity Framework: It is a set of .NET APIs used in software development for
performing data access. It is Microsoft's official tool for accessing data.
Comparison
According to NuGet downloads and performance, Dapper is the world's most popular
Micro ORM. In contrast, Entity Framework is significantly slower than Dapper.
In comparison to other ORMs, such as the Entity Framework, Dapper does not generate
as much SQL, but it does an excellent job mapping from database columns to CLR
properties.
Since Dapper uses RAW SQL, it can be difficult to code, especially when multiple
relationships are involved, but when a lot of data is involved and performance
matters, it is worth the effort.
Since Dapper uses IDbConnection, developers can execute SQL queries to the database
directly rather than put data in other objects as they do in Entity Framework.