Training

June 16, 2016 | Author: Dara Saquin | Category: Types, Presentations
Share Embed Donate


Short Description

C#...

Description

TRAINING 101: PROGRAMMING MADE EASY by John D. Woo

COURSE OUTLINE  PART I:

Advanced T-SQL Programming

 PART II:

Dapper – .Net Micro ORM

 PART III: LINQ  PART IV: Version Control System: SVN

2

ADVANCED T-SQL PROGRAMMING PART I

3

REQUIREMENTS  Software:

SQL Server

SQL Server Management Studio

 Others:

Basic Knowledge in SQL

PART I : ADVANCED T-SQL PROGRAMMING

4

WINDOW FUNCTION  Performs calculation that are somehow related to

the current row  Can use aggregate functions without GROUP BY

clause  Resulting row is the same with incoming row  Allows to simplify code PART I : ADVANCED T-SQL PROGRAMMING

5

WINDOW FUNCTION VS NORMAL SQL Example Records of Table School SchoolName

Department

InstructorCount

Griffin Hills

Math

3

Griffin Hills

Science

5

School of Rock

Music

5

DMC

IT

7

DMC

HRM

3

Berk

Magic

4

Berk

Dark Spell

3

PART I : ADVANCED T-SQL PROGRAMMING

6

WINDOW FUNCTION VS NORMAL SQL Desired Output SchoolName

Department

InstructorCount

TotalInstructors

Griffin Hills

Math

3

8

Griffin Hills

Science

5

8

School of Rock

Music

5

5

DMC

IT

7

10

DMC

HRM

3

10

Berk

Magic

4

7

Berk

Dark Spell

3

7

PART I : ADVANCED T-SQL PROGRAMMING

7

WINDOW FUNCTION VS NORMAL SQL Normal SQL Solution: SELECT a.SchoolName, a.Department, a.InstructorCount, b.TotalInstructors FROM School AS a INNER JOIN ( SELECT SchoolName, SUM(InstructorCount) AS TotalInstructors FROM School GROUP BY SchoolName ) AS b ON a.SchoolName = b.SchoolName PART I : ADVANCED T-SQL PROGRAMMING

8

WINDOW FUNCTION VS NORMAL SQL Window function Solution: SELECT SchoolName, Department, InstructorCount, SUM(InstructorCount) OVER (PARTITION BY SchoolName) AS TotalInstructors FROM School

PART I : ADVANCED T-SQL PROGRAMMING

9

WINDOW FUNCTION Syntax:

function(col) OVER (PARTITION BY col ORDER BY col)

PART I : ADVANCED T-SQL PROGRAMMING

10

WINDOW FUNCTION function(col) OVER (PARTITION BY col ORDER BY col)

The function that will be used in the statement. This can be Aggregate, Ranking, or Analytic functions. PART I : ADVANCED T-SQL PROGRAMMING

11

WINDOW FUNCTION function(col) OVER (PARTITION BY col ORDER BY col)

The OVER clause indicates that the function will be used as a windowing function. PART I : ADVANCED T-SQL PROGRAMMING

12

WINDOW FUNCTION function(col) OVER (PARTITION BY col ORDER BY col)

The PARTITION BY clause performs similar to a GROUP BY clause. This is also called QueryPartition clause. It is sometimes optional depending on the function used in the sql statement. PART I : ADVANCED T-SQL PROGRAMMING

13

WINDOW FUNCTION function(col) OVER (PARTITION BY col ORDER BY col)

The ORDER BY clause is used to sort rows. It is also sometimes optional depending on the function used in the sql statement. PART I : ADVANCED T-SQL PROGRAMMING

14

WINDOW FUNCTION (AGGREGATE) MAX(col) OVER (PARTITION BY … ORDER BY …)

 SQL Server 200? (used as window function)  Returns the maximum value in the expression

PART I : ADVANCED T-SQL PROGRAMMING

15

WINDOW FUNCTION (AGGREGATE) SUM(col) OVER (PARTITION BY … ORDER BY …)

 SQL Server 200? (used as window function)  Returns the quantity in the expression

PART I : ADVANCED T-SQL PROGRAMMING

16

WINDOW FUNCTION (RANKING) ROW_NUMBER( ) OVER (PARTITION BY … ORDER BY …)  SQL Server 2005+  Returns the sequential number of a row within a

partition of a result set, starting at 1 for the first row of each partition PART I : ADVANCED T-SQL PROGRAMMING

17

WINDOW FUNCTION (RANKING) DENSE_RANK( ) OVER (PARTITION BY … ORDER BY …)  SQL Server 2005+  Returns the rank of rows within a partition of a

result set, without any gaps in the ranking.

PART I : ADVANCED T-SQL PROGRAMMING

18

WINDOW FUNCTION (ANALYTIC) LEAD(col) OVER (PARTITION BY … ORDER BY …)  SQL Server 2012+  Accesses data from a subsequent row in the same

result set without the use of a self-join

PART I : ADVANCED T-SQL PROGRAMMING

19

WINDOW FUNCTION (ANALYTIC) LAG(col) OVER (PARTITION BY … ORDER BY …)  SQL Server 2012+  Accesses data from a previous row in the same

result set without the use of a self-join

PART I : ADVANCED T-SQL PROGRAMMING

20

COMMON TABLE EXPRESSION  Similar to derived table but the result is not stored

as an object and last only for the duration of the query  Temporary named result set that can be reference

within a SELECT, INSERT, UPDATE and DELETE statement

PART I : ADVANCED T-SQL PROGRAMMING

21

COMMON TABLE EXPRESSION Useful functions:  Can be used recursively  Substitute for a View  Can be used to reference the resulting table

multiple times

PART I : ADVANCED T-SQL PROGRAMMING

22

COMMON TABLE EXPRESSION Basic syntax: WITH ctename AS ( .. CTE query definition .. ) .. SELECT/INSERT/UPDATE/DELETE .. PART I : ADVANCED T-SQL PROGRAMMING

23

MERGE CLAUSE MSDN DOC  Performs insert, update, or delete operations

on a target table based on the results of a join with a source table.

PART I : ADVANCED T-SQL PROGRAMMING

24

MERGE CLAUSE  You can use MERGE to perform these

operations: Conditionally insert or update rows in a target

table. If the row exists in the target table, update one or more columns; otherwise, insert the data into a new row.

Synchronize two tables. PART I : ADVANCED T-SQL PROGRAMMING

Insert, update, or delete rows in a target table based on

25

MERGE CLAUSE Basic syntax: MERGE Target AS T USING Source AS S ON (… your condition here …) WHEN NOT MATCHED BY TARGET THEN … insert into target table … WHEN MATCHED THEN … update target table … WHEN NOT MATCHED BY SOURCE THEN … delete from source … OUTPUT $action, inserted.*, deleted.*; PART I : ADVANCED T-SQL PROGRAMMING

26

STORED PROCEDURE  Similar to procedures in other programming

languages in which they can: Accept input parameters Contain programming statements that perform

operations in the database

PART I : ADVANCED T-SQL PROGRAMMING

27

ADVANTAGES OF STORED PROCEDURE  Performance  Productivity and Ease of use  Maintainability  Security

PART I : ADVANCED T-SQL PROGRAMMING

28

STORED PROCEDURE Basic syntax: CREATE PROCEDURE procedureName parameters type,.. AS BEGIN … your procedure script … END

PART I : ADVANCED T-SQL PROGRAMMING

29

QUESTION

30

DAPPER - .NET MICRO ORM PART II

31

REQUIREMENTS  Software:

Visual Studio

 Others:

Basic Knowledge in SQL

Knowledge in C#

PART II : DAPPER - .NET MICRO ORM

32

ORM  means Object Relational Mapping  Programming technique for converting data

between incompatible type systems in relational databases and object-oriented programming languages  Creates “Virtual Object Database” that will be

used within the programming language PART II : DAPPER - .NET MICRO ORM

33

LIST OF ORM  Entity Framework - .Net  nHibernate – Java, .Net  CakePHP – PHP  DatabaseObjects – MonoDroid, iOS  ActiveJDBC – Java PART II : DAPPER - .NET MICRO ORM

34

SAMPLE CODE  Using Entity Framework var contact = context.People.Where(x => x.ID == 1).Single();

 Using Dapper string sql = “SELECT * FROM People WHERE ID = @ID”; var contact = db.Query(sql, new { ID = 1});

PART II : DAPPER - .NET MICRO ORM

35

PROS  Making data access more abstract and

portable  Speed development  Sanitizing, automatically parameterize query to avoid SQL injection  You don’t need to write poor SQL code  Use OOP goodness like data inheritance without headache PART II : DAPPER - .NET MICRO ORM

36

CONS  You have to learn it, they are not lightweight

tools.  You should know how to set it up.  Performance are ok with simple queries but doesn’t perform well on large databases.  Language specific.  It abstract the DB. PART II : DAPPER - .NET MICRO ORM

37

MICRO ORM  Small, lightweight and easy to use  Requires less configuration  Similar performance to a raw SqlCommand

with DataReader parsing

PART II : DAPPER - .NET MICRO ORM

38

ORM PERFORMANCE SELECT mapping over 500 iterations Framework

Duration

Hand Coded (SqlDataReader)

47 ms

Dapper

49 ms

OrmLite

50 ms

PetaPOCO

52 ms

nHibernate

104 ms

Linq2Sql

181 ms

Entity Framework

631 ms

PART II : DAPPER - .NET MICRO ORM

39

LIST OF SOME POPULAR MICRO ORM  Dapper by Sam Saffron  Massive by Rob Connery  Simple.Data by Mark Rendle  Peta Poco by Top Ten Software PART II : DAPPER - .NET MICRO ORM

40

DAPPER  Designed for Speed  Originally developed by Sam Saffron and Marc

Gravell  https://github.com/StackExchange/dapper-dotnet  Single file you can drop in to your project that will extend your IDbConnection interface PART II : DAPPER - .NET MICRO ORM

41

DAPPER  Static and dynamic mapping  Supports raw SQL and Stored Procedure  Supports the following RDBMS: SQL Server,

MySQL, Oracle, Sqlite, SqlCe, Firebird, etc..

PART II : DAPPER - .NET MICRO ORM

42

POPULAR SITES THAT USE DAPPER  www.stackoverflow.com  Xapfest  http://www.jitbit.com/web-helpdesk/

and a lot more.. PART II : DAPPER - .NET MICRO ORM

43

DAPPER INSTALLATION Two types on installation  Using Raw File  Using NuGet

PART II : DAPPER - .NET MICRO ORM

44

DAPPER INSTALLATION Using Raw File  Visit this link: https:// github.com/StackExchange/dapper-dot-net/tree/master/Dapper%20NET40

 Download SqlMapper.cs PART II : DAPPER - .NET MICRO ORM

45

DAPPER INSTALLATION

DOWNLOAD PART II : DAPPER - .NET MICRO ORM

46

DAPPER INSTALLATION  Add the file in your project

PART II : DAPPER - .NET MICRO ORM

47

DAPPER INSTALLATION Using NuGet (Preferred method)  Right Click the Project and select Manage

NuGet Packages

PART II : DAPPER - .NET MICRO ORM

48

DAPPER INSTALLATION  Type Dapper, select that was created by Sam

Saffron and Marc Gravell and click Install

PART II : DAPPER - .NET MICRO ORM

49

DAPPER INSTALLATION  After Dapper has been installed, you need to

declare its namespace so it will add extension methods on IDbConnection interface. using Dapper;

PART II : DAPPER - .NET MICRO ORM

50

DAPPER DEMO  Basic List Query  Adding Parameters  CRUD operations  Stored Procedures  Bulk Insert  List Support PART II : DAPPER - .NET MICRO ORM

51

QUESTION

52

LINQ PART III

53

REQUIREMENTS  Software:

Visual Studio

 Others:

Basic Knowledge in SQL

Knowledge in C#

PART III: LINQ

54

EXTENSION METHOD  A method added to an object, often called a class,

after the original object is compiled.  It makes your code cleaner.

PART III: LINQ

55

EXTENSION METHOD INDICATOR

PART III: LINQ

56

CREATING EXTENSION METHOD  The class as well as the method needs to be

static. public static class Extension { public static string AllUpperCase(this string value) { return value.ToUpper(); } } PART III: LINQ

57

LINQ  Language Integrated Query  Technique for querying data that is integrated into

.Net languages such as C# and VB  It has a single unitive syntax to query against

various data source  It is transformative, in that the results of linq

query in one datasource can be morphed into another type.

PART III: LINQ

58

ADVANTAGES OF LINQ  Type-Safe, Strongly Type  Intellisense  Reduction in work  Easy debugging  Support many datasource PART III: LINQ

59

SYNTAX Query Syntax  SQL-like

IEnumerable result = from c in orders where c.OrderID == 1 select c;

PART III: LINQ

60

SYNTAX Method Syntax  Lambda Expression

IEnumerable result = orders .Where(c => c.OrderID == 1);

PART III: LINQ

61

STANDARD QUERY OPERATORS Type

Method

Filtering

Where

Projection

Select, SelectMany

Ordering

OrderBy, ThenBy

Grouping

GroupBy

Quantifiers

All, Any

Partitioning

Take, Skip

Sets

Union, Concat, Intersect, Except

Elements

First, FirstOrDefault, Single

Aggregation

Count, Sum, Max

Conversion

ToArray, ToLIst

Casting

OfType

PART III: LINQ

62

QUESTION

63

VERSION CONTROL SYSTEM: SVN PART IV

64

MANUAL WAYS OF ORGANIZING FILES File History Name 1.) by Appending extra text

2.) by Appending date/time

• hello.cs

• hello-20140802.cs

• hello.back1.cs

• hello-20140802-1530.cs

• hello.back1.-minor.cs

• hello-20140803-1025.cs

• hello.final.cs • hello.final.promise.cs

PART IV : Version Control System - SVN

65

MANUAL WAYS OF ORGANIZING FILES Saving to different locations • CD/DVD • Flash Drive • External Harddisk • Sending via Email

PART IV : Version Control System - SVN

66

MANUAL WAYS OF ORGANIZING FILES Problems:  Difficult to track the changes between files  Hard to identify which one is the latest  Hard to rollback changes to specific state.  When working on the team, it takes too much time to

combine the files. PART IV : Version Control System - SVN

67

VERSION CONTROL SYSTEM  A central place to store and manage historical changes  Manage file with version, allowing recovering of desired

state  Facilitates collaboration among development team

members  Easy to check out prior code, undo changes  Supports Authentication and Authorization PART IV : Version Control System - SVN

68

ADVANTAGES  Allows team to easily track historical changes within file  Shared on multiple workstation  Automatic backup  Allows collaborators to work efficiently  Easily change between file states

PART IV : Version Control System - SVN

69

SVN  Abbreviation for SUBVERSION  open source version control system  Managed files are place in a repository  Allows you to recover old versions of your data, examine

the history of what, where, when, and who – changes the file  Supported in most operating system PART IV : Version Control System - SVN

70

BASIC STRUCTURE

PART IV : Version Control System - SVN

71

COMMON FUNCTIONALITIES  Update/Update to revision  Commit  Revert  Import/Export  Show Logs  Lock/Unlock  Clean Up  Unversion/Ignore PART IV : Version Control System - SVN

72

TOOL USED SVN SERVER – Visual SVN Server

(http://

www.visualsvn.com/server)

PART IV : Version Control System - SVN

73

TOOL USED SVN CLIENT – TortoiseSVN(http://tortoisesvn.net/downloads.html)

PART IV : Version Control System - SVN

74

TOOL USED  Other SVN Client/Plugins  Visual Studio  Visual SVN - http://www.visualsvn.com/visualsvn/  AnkhSVN - https://ankhsvn.open.collab.net/

 Eclipse

Eclipse Subversive - https://www.eclipse.org/subversive/  Subclipse - http://subclipse.tigris.org/ 

PART IV : Version Control System - SVN

75

DEMONSTRATION  SVN Server Installation  Creating Users  Creating Repository  SVN Client Installation  Perform Common Functionalities  Update  Commit  Revert  Show Logs  etc…

PART IV : Version Control System - SVN

76

QUESTION

77

THANK YOU AND HAPPY CODING! 78

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF