MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... · Oracle Client OLE DB Managed ......

45
B Nagaraju http://nbende.wordpress.com

Transcript of MVC 4.0, Knockout.js, Bootstrap and EF6 - Nagaraj's .NET ... · Oracle Client OLE DB Managed ......

B Nagaraju

http://nbende.wordpress.com

B Nagaraju

http://nbende.wordpress.com

Agenda

B Nagaraju

http://nbende.wordpress.com

What to expect in this session

• Complete ADO.NET Support available in .NET

• Clear Conceptual View Supported by Demos

• Understand 3 generations of DataAccess .NET

• Around 9 minutes of videos

• Free Stuff

B Nagaraju

http://nbende.wordpress.com

Let’s Start with a small video about

Microsoft Today

from Top Fortune companies

B Nagaraju

http://nbende.wordpress.com

Free Stuff for

workshop attendees!

Get Free Material of

ADO.NET with Conceptual

Explanation and Practical

Examples ( Registrants ) for all

versions

B Nagaraju

http://nbende.wordpress.com7

Data Access Architecture

ODBC

OLE DB

ADO ADO.NET

SQL ClientOracle Client

OLE DB

Managed

Provider

B Nagaraju

http://nbende.wordpress.com8

ADO.NET and the .NET Framework

Microsoft .NET Framework

Common Language Runtime

Base Classes

Web Services User Interface

Data and XML

ADO.NET XML ... ...

B Nagaraju

http://nbende.wordpress.com9

ADO vs. ADO.NET 1/2

ADO

– Designed for connected access

– Tied to the physical data model

– The RecordSet is the central data container

– RecordSet is one (1) table that contains all the data

Retrieving data from > 1 table or source requires a database JOIN

Data is “flattened”: lose relationships; navigation is sequential

– Data types are bound to COM/COM+ data types

– Data sharing via COM marshalling

– Problems marshalling through firewalls (DCOM, binary)

B Nagaraju

http://nbende.wordpress.com10

ADO vs. ADO.NET 2/2

ADO.NET

– Designed for disconnected access

– Can model data logically!

– The DataSet replaces the RecordSet

– DataSet can contain multiple tables

Retrieving data from > 1 table or source does not require a JOIN

Relationships are preserved: navigation is relational

– Data types are only bound to XML schema

– No data type conversions required

– XML, like HTML, is plaintext: “Firewall friendly”

B Nagaraju

http://nbende.wordpress.com11

Connected Layer

The term connected layer implies that a connection to a data

source is open while data is being analyzed or manipulated.

ADO.NET does not support connected data operations. (few

Read-Only actions are connected)

Persistent connections must be made using the COM Interop

modules with the older ADO, and OLE DB Libraries to work in

connected manner.

B Nagaraju

http://nbende.wordpress.com12

Disconnected Layer

By its very nature, ADO.NET is disconnected, which means a

connection to the data source is not maintained.

A disconnected layer allows our data source to free up resources

and respond to the next user.

B Nagaraju

http://nbende.wordpress.com13

ADO .NET Architecture

ADO .NET Architecture is the latest extension of the Universal Data

Access technology from Microsoft that uses textual formatting

instead of binary formatting.

In ADO .NET Architecture data is accessed and manipulated in a

connectionless manner by using data providers.

The Command, Connection, DataReader, DataAdapter & DataSet

are the core objects in ADO.NET. They form the basis for all

operations regarding data in .NET.

B Nagaraju

http://nbende.wordpress.com14

Presentation Tier

Windows Forms

DataSet

MyApp.Exe

Business Tier Data TierWeb Forms

Business to Business

Data Object (Class)

DataSet

DataSet

Internet

Intranet Data Adapter

Data Adapter

(BizTalk, for example)

XML

IE

WPF Forms

Typical Implementation of Classical ADO.NET in Projects

B Nagaraju

http://nbende.wordpress.com15

ADO ADO .NET

RecordSet DataReader

DataAdapter

DataSet

Command Command

ConnectionConnection

B Nagaraju

http://nbende.wordpress.com16

Data Access Namespaces in .NET

• System.Data

• System.Data.OleDb

• System.Data.SQLClient

• System.Data.OracleClient

• System.Data.XML

ADO.NET

System.Data

.OleDb.SqlClient.SqlTypes .Common

B Nagaraju

http://nbende.wordpress.com17

DataBase Classes/Objects in ADO.NET

• OleDbConnection /SQLConnection/Oracle..

• OleDbCommand/SQLCommand/Ora..

• OleDbDataAdapter/SQLDataAdapter/Ora..

• OleDbParameter/SQLParameter/Ora..

• DataSet

• DataTable

• DataView

• DataRow

• DataColumn

B Nagaraju

http://nbende.wordpress.com18

Programming with ADO.NETConnection

• Represents A Connection To The Data Source

• On A Connection, You Can…

– Customize the connection to the database

– Create a Command object associated with the connection

– Begin, commit, and abort transactions

• Equivalent To The ADODB.Connection Object

B Nagaraju

http://nbende.wordpress.com19

Command Object

• Responsible for Invoking Stored Procedures from

Database

• Also used for running SQL Commands like

Insert,Update,Delete Statements

B Nagaraju

http://nbende.wordpress.com20

• Represents a Command To Be Executed

– Not necessarily SQL

• With An ADO.NET Command You Can:

– Define a statement to be executed on the server

– Set parameter information for that command

– Retrieve return values from command execution

• Corresponds To ADODB.Command Object

• May Contain Parameters

– Values to be used when executing a statement

Command Object

B Nagaraju

http://nbende.wordpress.com21

• ExecuteNonQuery

• ExecuteReader

• ExecuteScalar

• ExecuteXmlReader(for SqlCommand object only)

Command Object

• BeginExecuteNonQuery

• BeginExecuteReader

• BeginExecuteScalar

• BeginExecuteXmlReader(for SqlCommand object only)

B Nagaraju

http://nbende.wordpress.com22

DataReader Object

• DataReader provides forward-only and read-

only streams of data

– Represents results of an executed query or command

• Equivalent to a FO/RO RecordSet

– Doesn't support scrolling or updating

• Supports Databinding

B Nagaraju

http://nbende.wordpress.com23

DataSet Object

a client-side database….

B Nagaraju

http://nbende.wordpress.com24

• Equivalent of ADO RecordSet but Richer

• Relational views of data

– Contains tables, columns, rows, constrnts, views, relations

• Disconnected model

– Has no knowledge of data source

– Array-like indexing, Strong typing

– Supports Databinding

– Supports batch updates

– Connects to data source via DataAdapter

DataSet Object

B Nagaraju

http://nbende.wordpress.com25

DataAdapter

• Manages Data Exchange Between DataSet and Data Source

– Fill()

– Update()

• Provides Mappings Between Tables & Columns

• User Can Override Insert/Update/Delete

Commands (Autogen component available)

• Allows Single DataSet To Be Populated From

Multiple Different Datasources

B Nagaraju

http://nbende.wordpress.com26

Database

DataAdapter

SelectCommand

InsertCommand

UpdateCommand

DeleteCommand

TableMappings

DataSet

DataSet & DataAdapter

B Nagaraju

http://nbende.wordpress.com27

DataSet

Tables

Table

Columns

Column

Constraints

Constraint

Rows

Row

Relations

Relation

B Nagaraju

http://nbende.wordpress.com

OriginalDataStore

DataSet

Table1

Table2

Sets uprelationships

DataSet

Table1

Table2

Makes changesto data

DataSet

Table1

Table2

Resolves changeswith ManagedProvider

Extracts tablesWith Managed

Provider

Connected

Operations

Disconnected

Operations

D

a

t

a

S

e

t

B Nagaraju

http://nbende.wordpress.com

Demo

B Nagaraju

http://nbende.wordpress.com30

Benefits of ADO.NET 2.0

Interoperability through use of XML

– Open standard for data that describes itself

– Human readable and decipherable text

– Used internally but accessible externally (Can use XML to read and write and move data)

Scalability through the disconnected DataSet

– Connections are not maintained for long periods

– Database locking does not occur

Locking support with ServiceComponents - Optimistic locking otherwise

– Works the way the Web works: “Hit and Run!”

Maintainability

– Separation of data logic and user interface

Objects

<book>

<title/>

<author/>

<year/>

<price/>

</book>

XML

.NET Language Integrated Query

C# 3.0 VB 9.0 Others…

Relational

LINQ to

Objects

LINQ to

SQL

LINQ to

XML

LINQ to

Entities

LINQ to

DataSets

B Nagaraju

http://nbende.wordpress.com

• The Good

– Easy to use

– Very powerful for read operations

– Absolutely recommended for 2-tier app

– Good for most ASP.NET architectures

• Where Data Access Layer and Presentation

Layer are in the same process

– Released

B Nagaraju

http://nbende.wordpress.com

• The Bad The Challenging

– Change tracking in stateless environment (ASP.NET)

– Understand when query are executed and how

– Lazy vs. Eager Loading

• The Ugly

– Doesn't have multi tier change tracking support

– ADO.NET Entity Framework is an alternative

– Works only with SQL Server

B Nagaraju

http://nbende.wordpress.com

• Use the SQL Profiler all the time!!• Use the SQL Profiler all the time!!

• Use the SQL Profiler all the time!!

• Use the SQL Profiler all the time!!

• Use the SQL Profiler all the time!!

• Use the SQL Profiler all the time!!

• Use the SQL Profiler all the time!!

• Use the SQL Profiler all the time!!

• Use the SQL Profiler all the time!!

• Use the SQL Profiler all the time!!

B Nagaraju

http://nbende.wordpress.com

B Nagaraju

http://nbende.wordpress.com

OLD ADO.NET 2.0 Linq To Sql Entity Framework

B Nagaraju

http://nbende.wordpress.com

EntityFramework Versions

Entity Framework 3.5 SP1

Entity Framework 4

Entity Framework 4.1 -> 4.3

Entity Framework 5

Entity Framework 6 -> 6.1.1

Core runtime in .NET Framework

Newer runtime pieces out-of-band (NuGet)

Tooling in Visual Studio

Runtime in .NET Framework

Tooling in Visual Studio

Runtime out-of-band (NuGet)

Tooling out-of-band (Microsoft Download Center)

Latest version “chained in” to new Visual Studio releases

Entity Framework 6.1.2

Entity Framework 7

B Nagaraju

http://nbende.wordpress.com

B Nagaraju

http://nbende.wordpress.com

3-Layer / Typed DataSet

Presentation::Screen

BusinessLogic::[X]BM

+Get()

+GetByID()

+Commit()

+DoSomeInterestingBusinessProcessing()

BusinessLogic::[Y]BM

System::System.Data.DataSet

DataManagers::[A]DM

#FillDataTableByDynamicSql()

#FillDataByStoredProcedure()

#PerformInsert()

#PerformUpdate()

#PerformDelete()

QueryManagers::QmBase

QueryManagers::[M]QM

+Fill()

+FillByID()

+Insert()

+Update()

+Delete()

QueryManagers::[N]QM

+Get()

+GetByID()

+Commit()

DataManagers::[B]DM

Database

Database::Stored Procedure

Presentation Business Logic (Orchestration) Data Access

DatabaseBusiness Objects /

Data TransportBusinessObjects::[B]DS

BusinessObjects::DataTable[N]

BusinessObjects::DataTable[M]

One DM per DataSet.

Contains logic for

ordering operations

and controlling all

DataTables in the

DataSet.

One QM per DataTable.

Contains logic for basic

database operations for

each table or query

Contains business rules

and logic at the process or

use-case level.

Contains

business rules

at the entity

level.

Presentation::Service

B Nagaraju

http://nbende.wordpress.com

3-Layer / Entity Framework

Presentation::Screen

BusinessLogic::[X]BM

+Get()

+GetByID()

+Commit()

+DoSomeInterestingBusinessProcessing()

BusinessLogic::[Y]BM

Database

Database::Stored Procedure

Presentation Business Logic (Orchestration) Data Access (Entity Framework)

DatabaseBusiness Objects /

Data TransportBusinessObjects::[EntityA]

Contains business rules

and logic at the process or

use-case level.

Contains

business rules

at the entity

level.

Presentation::Service

This layer is implemented

through configuration using:

* Conceptual Model

* Storage Model

* Mapping Spec

B Nagaraju

http://nbende.wordpress.com

Demo

B Nagaraju

http://nbende.wordpress.com

B Nagaraju

http://nbende.wordpress.com

Links

• Team blog of Microsoft – blogs.msdn.com/adonet

• Documentation – https://msdn.microsoft.com/en-US/data/ef

• EF6 Project – EntityFramework.codeplex.com

• EF7 Project – github.com/aspnet/EntityFramework

• http://nbende.wordpress.com http://www.DurgaSoft.com

• Twitter – @nbende

• Facebook – facebook.com/nbende

B Nagaraju

http://nbende.wordpress.com

Thank You….!Don’t Miss…..Coming Workshops

• DevOps - Agile

• Cloud Computing

• Angular 2.0/React JS

• .NET 2015 in your apps

• Universal Apps/Mobile Apps

and more..

B Nagaraju

http://nbende.wordpress.com

Questions?