generating the.net business and data layers andrew novick visual basic pro user group october 2,...

63
Generating the .Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

Upload: astrid-fitzgerald

Post on 31-Mar-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

Generating the .Net Business and Data Layers

Andrew Novick

Visual Basic Pro User Group

October 2, 2003

Page 2: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 2

Agenda

The n-Tier Model DeKlarit Paradigm

Building the Model Generating the Code Using The Code

Demo of DeKlarit

Page 3: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 3

Novick Software

Consulting Company of Andrew Novick Project Management Business Applications Design Programming Coaching Training

Technologies: SQL Server, VB, VB.Net, ASP, ASP.Net, and XML

http://www.NovickSoftware.com

Page 4: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 4

The n-Tier Model

Web Server Code (ASP, ASP.Net)

Windows Client (WinForms)Browser

Business Objects

Data Services Layer

Data Storage Layer (SQL Server)

UI

Business

Data

Client

AppServer

Database

LogicalLayer

PhysicalLayer

*

*One possible configuration

Page 5: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 5

DeKlarit

Modeling and code generation tool for the business and data layer of an n-Tier application.

Current Version 2.2 Price: $899 Languages: C# & VB.Net Databases: SQL Server & Oracle Business Frameworks Add-ins Create Windows and Web Forms

Page 6: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 6

Alternatives

Commercial Products Freeware Shareware Write Your Own

Page 7: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 7

Commercial Products

DeKlarit ($899) Lockwood Tech’s ProcBlaster ($399) IronSpeed Designer ($495…$3,500) VBeXpress.Net ($450) RapTeir (Free…$299) AlachiSoft TierDeveloper ($495-$995) LLBLGenPro (Free…$195) ORM.Net ($495)

Page 8: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 8

Free/OpenSource

LLBGEN (there is a paid pro version) Olymeyrs OJB.Net (Pre-Alpha Port of a Java tool)

Page 9: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 9

Write Your Own

Writing Code To Write Your Data Services Layer Presented to VB Pro, December 2001 Based on VBPJ Article:

Automate Writing Stored Procedures June 2001

Available at http://www.NovickSoftware.com/Presentations

Implementing CRUD Operations Using Stored Procedures: Part 1on www.DatabaseJournal.com 10/7/03

Page 10: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 10

DeKlarit Paradigm

ModelingCode

GenerationApplication

Coding

Page 11: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 11

Concepts

Business Framework Business Components

Attributes Domains Rules Formulas Code Generation

Page 12: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 12

The Business Framework

An information model of a business that represents it’s behavior and structure.

A Model Consisting of A database schema DataAdapters to encapsulate business logic DataSets that will be used by UI layer

programmers.

Page 13: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 13

Business Component

Similar to an Object, Entity, or Structure May have repeating groups

(de-normalized)

Contains multiple attributes

Page 14: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 14

Attributes

Main elements of the Business Component Structure

Primary Element identifies the Business Component

Secondary Elements have data for the Business Component

Page 15: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 15

Primary Elements- Primary keys

Identify the Business Component instance

Must be unique

May not change

Must have a value from when the instance is created

Page 16: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 16

Universal Relation Assumption (URA)

One thing (attribute) has the same name everywhere.

When an attribute appears in two Business Components they are assumed to be related.

Page 17: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 17

URA – This won’t work

• Name used in both tables.

• Self-reference in UnitsDefinition (UnitsCD, DerivedFromUnitCD).

Page 18: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 18

URA - Subtypes

URA doesn’t always work Multiple relationships to the same component Self-references

Subtypes allow you to circumvent this restriction.

Page 19: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 19

Domains

Abstract data types that allow attributes to have consistent data types.

UI makes them hard to find.

Page 20: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 20

Data Types Supported

Characters   Char(length). Fixed length character string. VarChar(length). Variable length character string. Length is the

maximum length. Text.

Numeric(length [, decimals]) DateTime Date Blob Boolean GUID

Page 21: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 21

Subtypes – Multiple Relationships The Problem

Page 22: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 22

Subtypes – Multiple Relationships The Solution

Page 23: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 23

Hierarchical Business Component

* Source DeKlarit 2.2 Help

Page 24: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 24

DataProviders

Extract data from the Business Framework Read-only Attributes come from existing Business

Components

Essentially a Query or View

Page 25: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 25

DataProvider – Example

Page 26: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 26

DataProvider Features

Parameters Conditions Ordering Distinct

Page 27: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 27

Business Rules

Rules are declarative. Written in DeKlarit’s own syntax:

<Action> [IF <Condition>];

Page 28: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 28

Available Rules

Error Assign Default Static Method Call Add and Subtract Serial

Page 29: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 29

Error Rule

error( ExceptionName [, <StringExpr>] )

if <Condition> ;

Page 30: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 30

Error Rule Example

error( NoCashException, "Not enough available cash to buy the stock") if AccountAvailableCash < 0 and TradeBuySell = -1;

UI Would have this code:  try                        accountDataAdapter1.Update(accountDataSet1)                        catch (NoCashException e)                                    Label1.Text = e.Message

           end try

Page 31: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 31

Assign Rule

<Attribute> = <Expression>

[ if<Condition> ];

Page 32: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 32

Assign Rule Example

TradeCommission = 9.99 if insert and TradeAmount < 10000;

TradeCommission = 7.99 if and TradeAmount < 100000;

TradeCommission = 5.99 if insert and TradeAmount >= 100000;

Page 33: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 33

Issues with Assign Rules

They overlap with formulas and could be replaced by formulas.

Not recalculated as formulas are

Page 34: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 34

Default Rule

Default( <Attribute>, <Expression>);

Default(TradeCommission, 9.99);

Page 35: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 35

Default = Assignment

Attribute> = <Expression>

if insert and <Attribute>.IsNull();

Page 36: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 36

Static Method Call Rule

<StaticMethodCall> if <Condition> ;

MyNamespace.MyClass.MyStaticMethod(…) if insert;

Page 37: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 37

Add and Subtract Rule

add( <Attribute1>, <Attribute2> ); subtract( <Attribute1>, <Attribute2> );

Equivalent to assignment statements

Page 38: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 38

Serial Rule

Numbers an attribute

serial( <AttributeToBeNumbered>, <AttributeWhichHasTheLastValue>, <Increment> );

serial(InvoiceLineNumber, InvoiceLastLineNumber, 1);

Page 39: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 39

Formulas

Equation for calculating an attribute

Types Horizontal Vertical

Built-in Methods

Page 40: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 40

Horizontal Formulas

Formula = f( Att1, …, Attn);

The function may reference attributes in the table and static methods, including CLR methods such as System.Datetime.Now()

Usuall arithmentic operators Conditionals

Page 41: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 41

Horizontal Formula Example

TradeCurrentValue = TradeQty * StockLastPrice * TradeBuySell * -1;

Page 42: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 42

Conditionals in Horizontal Formulas

TradeNetAmount = TradeAmount – TradeCommission

if TradeBuySell = 1; (TradeAmount + TradeCommission) * -1

Otherwise;

Page 43: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 43

Vertical Formulas

Aggregates a value from another level

<VerticalFormula> ::= <VerticalFunction> [Where <Condition>];

AccountStockValue = SUM(TradeCurrentValue);

Page 44: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 44

Vertical Functions

SUM( <SummedAttribute>) COUNT( <CountedAttribute>) MAX( <AttributeToMaximize>

[, <ReturnedAttribute> ]) MIN( <AttributeToMinimize>

[,<ReturnedAttribute> ]) FIND( <AttributeToFind> )

Page 45: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 45

Max and Min

StockHighestTradedPriceAccount = MAX(TradePrice);

Optional parameter for retrieving an attributed associated with the Min or Max

StockHighestTradedPriceAccountID = MAX(TradePrice, AccountId);

Page 46: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 46

DeKlarit Project

Business Components Data Providers Tables Domains

Page 47: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 47

Database Changes

DeKlarit does more than other object generators:

In includes a database conversion tool

Page 48: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 48

Code Generation

When built, generates a Business Framework project

DataSet for each componentDataAdapter for each component

Page 49: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 49

The FreeDB Schema

Page 50: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 50

Add-In: WinForms Application

Press a button and Deklarit generates a simple data entry application for the Windows environment.

Page 51: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 51

Add-In: Web Forms Application

Press a button and DeKlarit generates a simple data entry application for ASP.Net

Page 52: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 52

Using the Business Framework in ASP.Net

The framework can be used in any .Net environment including ASP.Net

Page 53: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 53

Software Supported

Databases SQL Server Oracle

Visual Studio 2002 2003

Page 54: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 54

Issues with DeKlarit

Nonstandard modeling approach Business Rules Universal Relation Assumption

Not really n-Tier Produces a combined Business/Data Tier

No really Object Oriented Produces a data centric application

Limited support (e-mail or newsgroup)

Page 55: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 55

Minor Issues with DeKlarit

C# orientation (examples, help, etc) Mangled names in generated code Rough edges running Reverse engineering

Wizard and a few other UI features. Poor English in the help and in the error

messages.

Page 56: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 56

Great things about DeKlarit

Limited knowledge required to start Help is integrated with Visual Studio Code generated for you. Database change scripts written and executed

for you!

Page 57: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 57

Technical Support

E-Mail (Responded within 30 minutes)

Newsgroups and limited documents on their web site.

No phone support.

Page 58: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 58

DeKlarit

Be the first!

Page 59: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 59

Apress Curlingstone an Imprint of Wrox Download code from the book at

www.Curlingstone.com

Andrew Novick [email protected] 978-440-8126 www.NovickSoftware.com

Consulting - Project Management – Design - Programming - Training

SQL Server 2000 XML Distilled

Page 60: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 60

T-SQL UDF of the Week

Free newsletter about SQL Server User-Defined Functions

A CREATE FUNCTION script in every issue Additional information on UDFs

Find it athttp://www.NovickSoftware.com/UDFofWeek/UDFofWeek.htm

Page 61: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 61

T-SQL User-Defined Functions

The Book

Coming November 2003

Page 62: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 62

Novick Software

Consulting Company of Andrew Novick Project Management Business Applications Design Programming Coaching Training

Technologies: SQL Server, VB, VB.Net, ASP, ASP.Net, and XML

http://www.NovickSoftware.com Home of the T-SQL User-Defined Function of the Week

Page 63: Generating the.Net Business and Data Layers Andrew Novick Visual Basic Pro User Group October 2, 2003

© Copyright 2003 Andrew Novick All rights reserved www.NovickSoftware.com October 2, 2003 Page 63

Thanks for coming!

VB Pro Users Group