Tuesday, 6 December 2016

Getting Hierarchical data

1) Hierarchical Query using a Recursive CTE

The basic syntax structure for a CTE is shown below:

WITH MyCTE AS 

(SELECT EmpIDFirstNameLastName,ManagerID 

FROM Employee

WHERE ManagerID IS NULL )

SELECT *FROM MyCTE



Building a Recursive CTE

  WITH MyCTE AS 
  ( 
    SELECT EmpIDFirstNameLastNameManagerID FROM Employee
   WHERE ManagerID IS NULL 
   UNION ALL

    SELECT EmpIDFirstNameLastNameManagerID FROM Employee

    INNER JOIN MyCTE ON Employee.ManagerID MyCTE.EmpID WHERE Employee.ManagerID IS NOT NULL 

)
SELECT *FROM MyCTE


Using C#.Net


IList<Employee> GetEmployees(Employee manager)
{
    var result = new List<Employee>();

    var employees = _employeeDb.Employees
                               .Where(e => e.ManagerEmployeeNumber == manager.EmployeeNumber)
                               .ToList();

    foreach (var employee in employees)
    {
        result.Add(employee);
        result.AddRange(GetEmployees(employee));
    }

    return result;
}


2) What is SOLID?

SOLID are five basic principles whichhelp to create good software architecture. SOLID is an acronym where:-
  • S stands for SRP (Single responsibility principle
  • O stands for OCP (Open closed principle)
  • L stands for LSP (Liskov substitution principle)
  • I stands for ISP ( Interface segregation principle)
  • D stands for DIP ( Dependency inversion principle)
  • S stands for SRP (Single responsibility principle):- A class should take care of only one responsibility.
  • O stands for OCP (Open closed principle):- Extension should be preferred over modification.
  • L stands for LSP (Liskov substitution principle):- A parent class object should be able to refer child objects seamlessly during runtime polymorphism.
  • I stands for ISP (Interface segregation principle):- Client should not be forced to use a interface if it does not need it.
  • D stands for DIP (Dependency inversion principle) :- High level modules should not depend on low level modules but should depend on abstraction.

2) 

HTTPHTTPS
URL begins with “http://”URL begins with “https://”
It uses port 80 for communicationIt uses port 443 for communication
UnsecuredSecured
Operates at Application LayerOperates at Transport Layer
No encryptionEncryption is present
No certificates requiredCertificates require


1 comment: