Wednesday, November 4, 2015

Important Links

Can Help interview queshttp://www.questpond.com/

http://www.codeproject.com/Articles/526874/Repositorypluspattern-cplusdoneplusright

http://www.codeproject.com/Articles/990492/RESTful-Day-sharp-Enterprise-Level-Application#_Toc418969124

Nth highest Salary


MS Sql Query

DECLARE @N int
SET @N = 1  -- Change the value here to pick a different salary rank

SELECT Salary
FROM (
    SELECT row_number() OVER (ORDER BY SalaryDESC) as SalaryRank
          ,     Salary
    FROM tbl_Salary
            ) as SalaryCTE
WHERE SalaryRank = @N

OR


DECLARE @N int
SET @N = 1
SELECT DraftAmount
FROM tbl_DocumentParser
WHERE DraftAmount = (SELECT DISTINCT(DraftAmount)
FROM tbl_DocumentParser as e1
WHERE (@N) = (SELECT COUNT(DISTINCT(DraftAmount)
)
FROM tbl_DocumentParser as e2
WHERE e1.DraftAmount <= e2.DraftAmount))


LINQ Query

var employee = Employees
    .OrderByDescending(e => e.Salary)
    .Skip(1)
    .First();
If multiple employees may have equal salary and you wish to return an IEnumerable of all the employees with the second-highest salary you could do:
var employees = Employees
    .GroupBy(e => e.Salary)
    .OrderByDescending(g => g.Key)
    .Skip(1)
    .First();

MYSQL Query

SELECT DISTINCT salary
FROM employees
ORDER BY salary DESC
LIMIT 1,1 ;


Tuesday, October 20, 2015

The Solid Principal

S.O.L.I.D (This is an acronym introduced by Michael Feathers)
  •  Single Responsibility Principle (SRP)
  •   Open/Closed Principle (OCP)
  •   Liskov Substitution Principle (LSP)
  •   Interface Segregation Principle (ISP)
  •   Dependency Inversion Principle (DIP) 
Some Facts
OOP is a programming paradigm based on concepts of object whereas S.O.L.I.D. are the programing principles that tell us how to write good programs.
Design patterns are telling how to design our programs/software but on the other hand S.O.L.I.D are only principles to make our program clean.

Single Responsibility Principle (SRP)
A class should be designed for single responsibility and there should not be more than one reason to make changes to this class. The responsibility of this class should be completely tied/encapsulated by the class.

Wednesday, September 30, 2015

Back to Basics

Back to Basics

What is .Net 
- Is a software development platform by Microsoft. It provides tools and IDE to develop applications.

Dot Net different versions and what it provides/provided:
1.0 - VS .Net:  CLR, Object oriented web development, use of dll class libraries.
1.1 - VS .Net2003 : ASP and ADO enhancement, builtin controls for mobile, ODBC support and                     IPV6 support.

Wednesday, August 19, 2015

DTO- When, why and how




Patterns always have two parts: the how and the when.

A Data Transfer Object is an object that is used to encapsulate data, and send it from one subsystem of an application to another.
DTOs are most commonly used by the Services layer in an N-Tier application to transfer data between itself and the UI layer. The main benefit here is that it reduces the amount of data that needs to be sent across the wire in distributed applications. They also make great models in the MVC pattern.
Another use for DTOs can be to encapsulate parameters for method calls. This can be useful if a method takes more than 4 or 5 parameters.
When using the DTO pattern, you would also make use of DTO assemblers. The assemblers are used to create DTOs from Domain Objects, and vice versa.
The conversion from Domain Object to DTO and back again can be a costly process. If you're not creating a distributed application
One case where it is useful to use something like a DTO is when you have a significant mismatch between the model in your presentation layer and the underlying domain model.
The only argument against using DTOs is the additional work required to write and manage the number of resulting DTO classes. It is not, however, a simple matter of a programmer's laziness. In large projects, decoupling presentation from the service layer costs you hundreds of new classes.

Tuesday, August 18, 2015

Reflection and Dynamic keyword in C#

Disclaimer : It's self study material, either directly produced/copied or modified as needed to suit                              "MY" understanding. Giving specific credits is little difficult. In-case of any concern                            seeing your wordings being presented here , please feel free to write, will try to remove                        or  add credits as demanded.
Credits : C#,VB.Net books, article, blogs, msdn etc.

Thursday, August 6, 2015

Linq - Language Integrated Query

Disclaimer : It's self study material, either directly produced/copied or modified as needed to suit                              "MY" understanding. Giving specific credits is little difficult. In-case of any concern                            seeing your wordings being presented here , please feel free to write, will try to remove                        or  add credits as demanded.
Credits : C#,VB.Net books, article, blogs, msdn etc.
--------------------------------------------------------------------------------------------------------------------------
Introduction

LINQ is  programming language syntax that is used to query data. We can query any kind of data like xml, object etc.
It's a data access technology like ADO.Net
.NET Framework includes libraries that allow anyone to create a LINQ provider that can query any data source.

Tuesday, May 19, 2015

Lets start with DBMS

DBMS - Database Management Systems are computer software application that interacts with users, other applications and data storage (database). A general DBMS allows us to creation, querying, updates and maintenance of Database.

Database - is an integrated and organized collection of logically related records or files that are stored on computer system which consolidates previously stored data.

A database is made up of a collection of tables that stores a specific set of structured data. A table contains a collection of rows- refereed as records or tuples and Columns- refereed as attributes. Each column is designated to store a certain type of information.

Tuesday, May 12, 2015

Day to day need in Sql

1. Find SP containing text
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES 
WHERE ROUTINE_DEFINITION LIKE '%Foo%' 
AND ROUTINE_TYPE='PROCEDURE'
2. Find table with given column and it's length
SELECT Column_Name, Table_Name, Col_Length(Table_Name,Column_Name)
FROM INFORMATION_SCHEMA.Columns 
WHERE Column_Name LIKE '%Name%' 
3. Find SP containing text
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES 
WHERE ROUTINE_DEFINITION LIKE '%Foo%' 
AND ROUTINE_TYPE='PROCEDURE'
4. Change column size throughout DB with given Column Name
DEALLOCATE My_Cursor
DECLARE @COLUMN_NAME VARCHAR(100)
DECLARE @TABLE_NAME VARCHAR(100)
DECLARE @tabLen VARCHAR(100)
Declare @sql as VARCHAR(500)=''
DECLARE My_Cursor CURSOR  DYNAMIC OPTIMISTIC FOR
SELECT COLUMN_NAME,
 TABLE_NAME  , COL_LENGTH ( TABLE_NAME , COLUMN_NAME ) As tabLen
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE COLUMN_NAME LIKE '%TIN'
and COL_LENGTH ( TABLE_NAME , COLUMN_NAME )>-1
AND COL_LENGTH ( TABLE_NAME , COLUMN_NAME )<20
AND DATA_TYPE = 'varchar' 

OPEN  My_Cursor
FETCH NEXT FROM My_Cursor INTO @COLUMN_NAME,@TABLE_NAME,@tabLen
WHILE @@FETCH_STATUS <> -1
 BEGIN
  
 SET @sql=''
 SET @sql= 'ALTER TABLE '+@TABLE_NAME +
' ALTER COLUMN '+@COLUMN_NAME+' VARCHAR(20)'
 select @sql
 EXEC 
 ( @sql)
 
  
  
  
FETCH NEXT FROM My_Cursor INTO 
 @COLUMN_NAME,@TABLE_NAME,@tabLen
END


sqlcmd -S <server Name> -U sa -P sapassword -i inputquery_file_name -o outputfile_name


Restore DB from UNC Path

Restore DB from UNC Path

While restoring MS Sql DB from a UNC path we at times face an error saying

 - Can not find the path specified.

Cause :
This error is due to sql server not having access permission.

Issue can be resolved using following :


EXEC sp_configure 'show advanced options', 1
GO

-- Update currently configured values for advanced options.

RECONFIGURE
GO

-- To enable xp_cmdshell

EXEC sp_configure 'xp_cmdshell', 1
GO

-- Update currently configured values for advanced options.
RECONFIGURE
GO

EXEC xp_cmdshell 'NET USE Z: \\Path Password /USER:domain\uName'



Sunday, April 5, 2015

AngularJs

AngularJS is an open source web application framework. It was originally developed in 2009 by Misko Hevery and Adam Abrons. It is now maintained by Google.
Definition of AngularJS as put by its official documention is as follows:
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. Angular's data binding and dependency injection eliminate much of the code you currently have to write. And it all happens within the browser, making it an ideal partner with any server technology.
AngularJS is powerful javascript based development framework, gives an option to write clien side application in a clean MVC way. AngularJS automatically handles javascript code suitable for each browser.



Sunday, March 22, 2015

Entity framework vs enterprise library

Entity framework vs enterprise library


Generics

Generics

Generics is one of the most powerful feature provided in .Net 2.0. It allows us to create a type safe data structures, without actually committing to a single data type. It is similar to C++ templates.

Generics allows user to delay the specification of data types. We can create a class or method and actual data type is not specified until it is used. Thus it can work with any data type.
We write specification for the class or method, with a substitute parameter for data type. When compiler encounters this class/method/constructor , it generates code to handle specific data type.

Benefits :
Significance performance boost
Quality code
Re-use without type cast

Sunday, February 8, 2015

OOPs I Know it - II

3. Basic Concepts of Object Oriented Programming


  1. Objects
  2. Classes
  3. Data abstraction and encapsulation
  4. Inheritance
  5. Polymorphism
  6. Dynamic binding
  7. Message passing
3.1. Objects - a material thing that can be seen and touched.
Objects are smallest entity of a program. All you name is an object like table, chair or in programs user defined data , vectors, time and lists. When a program is executed, objects interact by sending messages to one another.
Any object can interact with any other object but they should be compatible to send message in type other object understand and similarly receive message 
Example : Student and marks are two objects, in a program student object may send a message to inquire his/her marks in turn marks object will send message by sending marks detail.

3.2.  Classes
Set or category of things, having some property or attribute.
Object contains data and code to manipulate data- so class is collection of objects of similar type.

3.3.  Data abstraction and encapsulation

The wrapping up of data and function into a single unit (called class) is known as encapsulation.
Data is not accessible to the outside world, and only those functions which are wrapped in the class can access it. These functions provide the interface between the object’s data and the program.
This insulation of the data from direct access by the program is called data hiding or information hiding.
Abstraction refers to the act of representing essential features without including the background details or explanation.
Attributes are some time called data members because they hold information. The functions that operate on these data are sometimes called methods or member function.

3.4.  Inheritance
Inheritance is the process by which objects of one class acquired the properties of objects of another classes. It supports the concept of hierarchical classification.
In OOP, the concept of inheritance provides the idea of reusability. This means that we can add additional features to an existing class without modifying it.

OOPs I know It - I

Disclaimer :
This is an educational material collected from internet, from different blogs/links/materials. Displaying credits is difficult as it was not directly copied from a website and put on this blog, instead it was noted down on paper several years ago and several years later being digitized.

OOP : Object Oriented Programming basic concepts and all one should know

Some History for name sake

POP :Procedure-Oriented Programming

  • Problem is viewed as a sequence of things that needs to be done to achieve any goal.
  • Procedure oriented programming basically consists of writing a list of instructions for the computer to follow, and organizing these instructions into groups known as functions.

Some Characteristics exhibited by procedure-oriented programming are:
  • Emphasis is on doing things (algorithms).
  • Large programs are divided into smaller programs known as functions.
  • Most of the functions share global data.
  • Data move openly around the system from function to function (using global variable).
  • Functions transform data from one form to another.
  • Employs top-down approach in program design

Drawbacks

  • In a multi-function program, many important data items are placed as global so that they may be accessed by all the functions. Global variables are always confusing and prone to change by function accessing it.
  • Another serious drawback with the procedural approach is that we do not model realworld problems very well. This is because functions are action-oriented and do not really corresponding to the element of the problem.

Object Oriented Paradigm 

  • OOP treats data as critical element and does not allow to flow freely around the system.
  • Ties data closely to the function operating it, and protects accidental modifications.
  • OOP allows decomposition of problems into number of smaller entities called "object" and builds data and function around this objects.
  • The data of an object can be accessed only by the function associated with that object. However, function of one object can access the function of other objects. 


Some of the features of object oriented programming are:


  • Emphasis is on data rather than procedure.
  • Programs are divided into what are known as objects.
  • Data structures are designed such that they characterize the objects.
  • Functions that operate on the data of an object are ties together in the data structure.
  • Data is hidden and cannot be accessed by external function.
  • Objects may communicate with each other through function.
  • New data and functions can be easily added whenever necessary.
  • Follows bottom up approach in program design.