Search This Blog

Tuesday, July 23, 2019

Difference Between IQueryable, IEnumerable, And IList In LINQ

 IEnumerable and IQueryable, both are interfaces to a .NET collection
 IQueryable is Subset of  IEnumerable  and inheritance IEnumerable 

 IQueryable executed all the filters on the server-side and fetched the records that are matching all conditions and filters


 the filter is not applied on the server side but first, it fetches all the records from the server and applies on the client side


IEnumerable is useful when we want to iterate the collection of objects which deals with in-process memory
Image 2 for IEnumerable vs IQueryable

IQueryable is useful when we want to iterate a collection of objects which deals with ad-hoc queries against the data source or remote database, like SQL Server

Image 3 for IEnumerable vs IQueryable

Thursday, July 18, 2019

The Difference Between ROW_NUMBER(), RANK(), and DENSE_RANK()

Row_Number()

Syntax
 Row_Number() Over( partition by clause order by clause)

This function will assign a unique id to each row returned from the query.

DECLARE @Table TABLE (
      Col_Value varchar(2)
)

INSERT INTO @Table (Col_Value)
      VALUES ('A'),('A'),('A'),('B'),('B'),('C'),('C');

SELECT
      Col_Value,
      ROW_NUMBER() OVER ( partition by col_value ORDER BY Col_Value) AS 'RowID'
FROM     @Table;   

OUTPUT


Col_Value     RowID
   A                 1
   A                 2
   A                 3
   B                 1
   B                 2
   C                 1
   C                 2

SELECT
      Col_Value,
      ROW_NUMBER() OVER ( ORDER BY Col_Value) AS 'RowID'

FROM     @Table;  


Col_Value     RowID
   A                 1
   A                 2
   A                 3
   B                 4
   B                 5
   C                 6
   C                 7


Rank() 
Syntax
Rank() Over( partition by clause order by clause)

Same  as Row_Number() except  provide same rank for equal rows and also gap  between the different rank we can avoid using Dense_Rank() keyword

Dense_Rank()  Provide same rank for equal rows   function do not have gap alway given consective Rank value

Syntax

Dense_Rank() Over( partition by clause order by clause)


How can improve Performance of stored procedure


  • Keep database object name short ,meaningful and easy to remember
  • Normalize data atleast upto 3rd form but not at the cost of query performance
  • Do not use those column in the select statement which are not required. Never user select * statement.
  •  Use primary key in the table to filter the data in where clause. Use execution plan to analyze the query
  • Use SET NOCOUNT ON at the beginning of your stored procedures  This statement is used to stop the message, which shows the number of rows affected by SQL statement like INSERT, UPDATE and DELETE It will remove this extra overhead from the network.
  • Use table variables instead of temporary tables.

What is Angular Directive

Directive are marker of DOM  tells compiler  to attach a specified behaviour to DOM  element
Angular js come some predefined directive

Directve List

ng-app
ng-model
ng-init
ng-repeat
ng-bind
ng-controller
ng-value
ng-show
ng-hide
ng-disabled
ng-required
ng-click


It will extend the functionality of HTML like range no,input length etc

Wednesday, July 17, 2019

Bundling and Minification MVC

Bundling is  a technique to improve performance by reducing the number of request to  the server
Instead of fetching all resource one by  one we create bundle and fetch bundle that bundle in one single resource

To add a new bundle we can use BundleConfig  file
In this file we use Bundlecollection  class Which is available in System.Web.Optimization
Bundle need to registered Global.asax


Render Bundle
To Create js bundle we use @Script.Render(path)
To Create css bundle we use @Styes.Render(path)

Minification is the process  of removing unnecessary  data without changing its functionality

This include removing
Comments
Extra Space
convert large variabe to small size

etc

Difference Between TRUNCATE, DELETE, And DROP In SQL

  • TRUNCATE and Drop  is a DDL command
  • DELETE is a DML command

  • DELETE operations can be rolled back (undone), while DROP and TRUNCATE operations cannot be rolled back

Data Annotations MVC

Data Annotations are attributes which are used to perform server side validations as well as client side   validations

Tuesday, July 16, 2019

Difference between Encapsulation and Abstraction

Abstraction is used to hiding the  unwanted data and giving only relevant data
Encapsulation means hide code and data to single unit protect from outside world

Abstraction  Outer Layout used to in term of design
e.g outer look of mobile like   screen  and Keypad button to dial the number

Encapsulation   Inner layout used  in term of implementation
e.g Inner implementation detail of  mobile phone screen ,keypad linked  circuit

MVC Life Cycle

 1 -When request hit Server from browser its  come global.asax  first start Application start registered bundle ,route ,filer 


 2 then request come routing
come
 3 MvcHandler

 4 IControllerfactory create  insantance of controller
5 CreateTtempDatProvider
6 Invoke Action Method
7 Authentication Fiter
8 Authorization Filter
9 Modal Binder
10 Execute ActionFilter and ActionMethod
11 execute resulte and execute filter
12 dispose controller




@Html.Raw MVC

@Html.Raw return   html format pass string inside render html format without encoding

    @Html.Raw("<h1>hello word</h1>")

Monday, July 15, 2019

Difference between == and === in JavaScript

The ‘==’ operator tests for abstract equality i.e. it does the necessary type conversions before doing the equality comparison.

But the ‘===’ operator tests for strict equality i.e it will not do the type conversion hence if the two values are not of the same type, when compared, it will return false.


x = 5  
x == 8 return false
x == "5" return true
x == 5  return true

x === 5   return true
x === "5"  return false

Sunday, July 14, 2019

Handle Error MVC

Asp.net MVC framework provies a built in filter  to handle exception and this filter is known
HandleError



To use HandleError  in MVC application following three things are required

  • Enable custom error in web config
  • Add Error.cshtml view in shared folder
  • Use HandleError at Action/Controller/Global

        [HandleError ]  // filter at action level
        public ActionResult Index()
        {
            throw new Exception("this is exception");
        }

OutputCache Filter MVC and Location property



  • It 's type of Action filter
  • This filter is used to cache data of particular action method  for a specific time 
  • To set the time use Duration property



       [OutputCache(Duration =20) ]    //Apply filter to Action Method
        public ActionResult Getdate()
        {
            return View();

        }

 //Apply filter to all  Action Method  inside controller
  
   [OutputCache(Duration = 20)]
    public class HomeController : Controller
    {
        // GET: Home
       
        public ActionResult Getdate()
        {
            return View();
        }
        public int gettime()
        {
            return DateTime.Now.Date.Day;
        }

    }

Location Property Caching when we cache data using output cache filter it need some loation  to store that data 

[OutputCache(Duration = 20,Location =System.Web.UI.OutputCacheLocation.Server)]
        public ActionResult Getdate()
        {
            return View();

        }

Fiter in MVC

Filters are attribute which  are used to perform some logic before and  after a Action Method is called
e.g
caching ,error handling,logging,permision many more etc
MVC  4 has four filter
MVC 5 has 5 filter

  • Authentication filter
  • Authorization filter
  • Action filter
  • Result filter
  • Exception filter
 Note  this  is also order of execution of filter
Can  we create own filters
Yes
There are three place where we can use filters  in  asp.net mvc

  • Action Method   : Any Filter apply Action method  work  only this filters
  • Controller : Filter may apply  Controler apply all Action Method  with in Controller
  • Global  Apply all Controller global.asax file

Authentication Filters

Authentication filter runs before any other filter or action method. Authentication confirms that you are a valid or invalid user

Authorization Filters

Authorization Filters are responsible for checking User Access

Action Filters 

Action Filter is an attribute that you can apply to a controller action or an entire controller

Result Filters

These filters contains logic that is executed before and after a view result is executed

ExceptionFilters




Friday, July 12, 2019

Polymorphism

Polymorphism is often expressed as 'one interface, multiple functions'

Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.
Static polymorhism:Function Overoading,Operator Overloading


Run time polymorphism or method overriding means same method names with same signatures different class.


Function Overlading   One Function Name overloaded with multiple job is kown as Function Overloading

void f1(int z);  //generate error
int f1(int a)

return type does not matter same or different
void f1(int z);  //ok
int   f1(double a)


public   int  print()  tricks
        {
            return 1;
        }

       public  void print(int i, int k, string abc)
        {
            Console.WriteLine("Printing int: {0}", i);
        }
     
      public   void print(double f)
        {
            Console.WriteLine("Printing float: {0}", f);
        }
      public   void print(string s)
        {
            Console.WriteLine("Printing string: {0}", s);
        }

Difference between Array and ArrayList

Array Array is a fixed length data structure whose length cannot be modified once array object is created.
ArrayList   ArrayList is dynamic in nature which means it can resize itself to grow when required.



Arrays can be multi-dimensional
ArrayList is single dimensional.

Iterating over an array is faster than iterating over an ArrayList.Iterating over an ArrayList is significantly slower in terms of performance.


Takes less memory than ArrayList to store specified elements or objects.Takes more memory than the Array to store objects.

Left Join,Right Join,Full Outer Join

CREATE TABLE LEFTTABLE
(
ID INT ,
NAME  NVARCHAR(50)
)
INSERT INTO LEFTTABLE VALUES(1,'MONU')
INSERT INTO LEFTTABLE VALUES(2,'SONU')
INSERT INTO LEFTTABLE VALUES(3,'SYAM')
INSERT INTO LEFTTABLE VALUES(4,'RAM')

CREATE TABLE RIGHTTABLE
(
ID INT ,
DEP  NVARCHAR(50)
)

INSERT INTO RIGHTTABLE VALUES(1,'COMPUTER')
INSERT INTO RIGHTTABLE VALUES(2,'COMERCE')

SELECT L.ID ,NAME ,DEP FROM LEFTTABLE L  left   JOIN RIGHTTABLE R ON L.ID=R.ID
 Out Put
 ID
 NAME
 DEP
1
 MONU
 COMPUTER
2
 SONU
COMERCE
3
 SYAM
Null
4
 RAM
Null

Thursday, July 11, 2019

What will happen if all the three segments of the "for loop" are missing?

It means the condition is true and the loop goes into infinite mode

How do you know how many users are online on a website?(asp.net)

Application Session variable can be used in global.asax to count. Increase variable on Session_Start and decrease variable on Session_End

What is a shared assembly

A shared assembly is an assembly that resides in a centralized location known as the GAC (Global Assembly Cache) and that provides resources to multiple applications. If an assembly is shared then multiple copies will not be created even when used by multiple applications.