Top Dotnet Developer Interview questions and answers for experience and fresher
Top Dotnet Developer Interview questions and answers
Entity Framework Questions
1. What is History Table in EF?
Answer: In EF Core, a history table is created automatically when you enable auditing or track changes in tables. It stores previous versions of rows when they are updated or deleted, providing an audit trail.
Example: You can implement it using Temporal Tables in SQL Server with EF Core 6+.
2. Migrate and Execute a SQL Script in EF
Answer: Yes, you can use EF Core migrations to apply a SQL script. EF allows custom SQL commands in migrations.
Example:
migrationBuilder.Sql("CREATE PROCEDURE MyProcedure AS BEGIN SELECT * FROM Employees END");
3. Selecting Data from Multiple Tables in EF
Answer: You can use Join in LINQ to select data from multiple tables.
Example:
var result = from emp in context.Employees
join dept in context.Departments on emp.DepartmentId equals dept.Id
select new { emp.Name, dept.DepartmentName };
4. Migration in EF
Answer: Migration is a way to update the database schema based on model changes in the code. The steps to migrate are:
1. Run Add-Migration MigrationName.
2. Run Update-Database to apply it to the database.
5. ADO.NET vs EF
Answer:
ADO.NET: More control over SQL and connections, faster for raw database access.
EF: Easier and faster to develop, handles object mapping, and works at a higher abstraction level.
When to Use: Use ADO.NET for high-performance scenarios, EF for rapid development.
6. Using Stored Procedures in EF
Answer: EF allows you to call stored procedures using FromSqlRaw.
Example:
var employees = context.Employees.FromSqlRaw("EXEC GetEmployees").ToList();
7. Connected and Disconnected Architecture in ADO.NET
Answer:
Connected: Maintains an open connection to the database while performing operations (DataReader).
Disconnected: Fetches data once and disconnects (DataSet).
Angular Questions
1. What Are Modules in Angular?
Answer: Modules in Angular are containers that group components, directives, services, etc. Every Angular application has at least one root module, AppModule.
2. Pure and Impure Pipes
Answer:
Pure Pipes: Pipes that do not mutate and always return the same result for the same input (e.g., UpperCasePipe).
Impure Pipes: Pipes that can return different results even if the inputs are the same (e.g., pipes with async keyword).
3. Dependency Injection in Angular
Answer: DI in Angular is a design pattern where a class receives its dependencies from external sources rather than creating them itself.
Example:
@Injectable({ providedIn: 'root' })
export class MyService { }
4. Data Binding in Angular
Answer: There are 4 types of data binding:
1. Interpolation: {{variable}}
2. Property Binding: [property]="expression"
3. Event Binding: (event)="handler"
4. Two-way Binding: [(ngModel)]="property"
5. Passing Data Between Multiple Components
Answer: You can pass data between components using:
1. @Input() decorator to pass data from parent to child.
2. @Output() decorator to pass data from child to parent using EventEmitter.
6. Writing Unit Test Cases in Angular
Answer: Angular uses Jasmine and Karma for unit testing.
Example:
describe('AppComponent', () => {
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
});
7. Router-Outlet in Angular
Answer: <router-outlet> acts as a placeholder in Angular where the routed component will be displayed.
8. Difference Between Observables and Promises
Answer:
Observable: Can emit multiple values over time (lazy evaluation).
Promise: Returns a single value when resolved (eager evaluation).
9. SPA (Single Page Application)
Answer: SPA is a web application that loads a single HTML page and dynamically updates the content without reloading the entire page.
10. Lazy Loading in Angular
Answer: Lazy loading is a technique in Angular where feature modules are loaded on demand (when the user navigates to them), reducing the initial load time of the application.
#dotnettechpro #dotnet #csharp
11. RxJS and Lifecycle Methods
Answer:
RxJS: Reactive Extensions for JavaScript is a library for reactive programming using Observables.
Lifecycle Methods:
1. ngOnInit(): Called once after the component's first initialization.
2. ngOnDestroy(): Called just before Angular destroys the component
These answers provide a solid overview of the concepts and will be useful for your interview preparation. Let me know if you need further clarification on any of these!
Comments
Post a Comment