presentation

Report
An Automated Object Relational Mapper
What is NetTiers



Discovered Indirectly While Using Mojo
NetTiers = Open Source = FREE
Backed by CodeSmith
 Template Driven Source Code Generator
CodeSmith = Commercial ($99 - older
versions are free, have $10 off coupon
 http://www.codesmithtools.com/
 Basically is a Complex CodeSmith
Template That Auto Generates N-Tier Web
Applications w/ relevant CRUD, validation,
unit-testing, deeploading (more later), etc.

CodeSmith Template Generators
NetTiers
 NHibernate
 PLINQO
 Wilson’s ORMapper
 APOSA
 See more at
http://www.codesmithtools.com/features/
frameworks.aspx

NetTiers Features






Generates a pre-compiled solution along
with separate projects and framework tiers
for your application
Creates Entities/Classes Based On Your
Defined DB Schema http://nettiers.com/database.ashx
Partial/Concrete Classes
nUnit testing
Very robust data API
Much more
Example Sites
DSA Site Inventory https://wsnet.colostate.edu/CWIS463/ds
a-sites/
 Diversity Library System http://wsnetdev.colostate.edu/CWIS165/
home
 RDS Exam Intake System http://wsnet.colostate.edu/cwis248/exam
s/

Observations

Has a bit of a learning curve (eg. Took me a
few days to understand how to make url
routing work in the framework)
 MOST IMPORTANT – Spend all the time you need
to get your DB schema right before generating




Know what you’re doing when regenerating
solution after a db schema change
I plan on using it for most any medium to large
project (at least when doing web forms). Is
overkill for small projects.
Guessing it made a (minimum) 20 hour job
take 2 hours for the DSA site inventory
Lot more to learn – only used a month or two
Let’s Build a Site




Db Schema – Nail This Down
Download/Install CodeSmith & NetTiers
Open the NetTiers template file (.cst)
Mandatory Fields:




SourceDB (YOUR SQL DB INSTANCE)
MappingFile
OutputDirectory (LOCATION OF PROJECT)
RootNameSpace (YOUR_SITE)
 http://nettiers.com/GettingStarted.ashx#CB:_AB
_Getting_Started_-_Required_Properties_0
Let’s Build a Site

Recommended Fields:
 SourceTables
 IncludeComponentLayer - ServiceLayer and





DomainModel (your business layer)
IncludedDatabaseFeatures – SQLServer2005
IncludeUnitTest - True
DataSourceEnableTransactionDefault – False
IncludeAtlasLibrary – (learned about today)
IncludeAtlasToolkit
Let’s Build a Site

Post Generation:
 Open VS and convert solution to rely on .net





4.0 if desired
Move UI files (App_Themes, Common,
MasterPage, SiteMap) over
Set Default Page to Admin/Default.aspx
Run solution
Demo Declarative Stuff
Demo Code Behind Stuff
To Demo

Declarative Stuff
 Add Exam Request (note ddls generated from
foreign keys)
 Search
 Export
 Edit
UserControls - DRY
 Code-Behind

 Using the ServiceLayer API
 http://nettiers.com/ComponentLayer.ashx
Validation –
ExamRequestsBase.generated






















/// <summary>
/// Assigns validation rules to this object based on model definition. This file is overwritten upon
regeneration!
/// </summary>
/// <remarks>This method overrides the base class to add schema related validation.</remarks>
protected override void AddValidationRules()
{
//Validation rules based on database schema.
ValidationRules.AddRule( CommonRules.NotNull,
new ValidationRuleArgs("CourseNumber", "Course Number"));
ValidationRules.AddRule( CommonRules.StringMaxLength,
new CommonRules.MaxLengthRuleArgs("CourseNumber", "Course Number", 256));
ValidationRules.AddRule( CommonRules.NotNull,
new ValidationRuleArgs("SectionNumber", "Section Number"));
ValidationRules.AddRule( CommonRules.StringMaxLength,
new CommonRules.MaxLengthRuleArgs("SectionNumber", "Section Number", 256));
ValidationRules.AddRule( CommonRules.StringMaxLength,
new CommonRules.MaxLengthRuleArgs("ExamDelivery", "Exam Delivery", 256));
ValidationRules.AddRule( CommonRules.StringMaxLength,
new CommonRules.MaxLengthRuleArgs("ExamReturn", "Exam Return", 256));
ValidationRules.AddRule( CommonRules.StringMaxLength,
new CommonRules.MaxLengthRuleArgs("TimeAllowed", "Time Allowed", 100));
}
Validation – EntityRequests.cs















Partial Class File Not Overwritten. More Info On Validation http://nettiers.com/EntityLayer.ashx
/**/
/// <summary>
/// Validates the exam date.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="e">The e.</param>
/// <returns></returns>
private bool ValidateExamDate(object target, Validation.ValidationRuleArgs e)
{
if ((this.ExamDate ?? DateTime.MinValue) < DateTime.Today)
{
e.Description = "The exam date must not be in the past.";
return false;
}
return true;


}
Going Forward
Add more unit tests
 Add Elmah library to effectively handle
application errors

 http://code.google.com/p/elmah/

Add Sandcastle Documentation Compiler
to tie comments together
 http://sandcastle.codeplex.com/
CSS-based pretty forms – pForm
 Blueprint CSS stylesheet resets
 OWASP, if necessary?

Useful Links
NetTiers on GoogleCode http://code.google.com/p/nettiers/
 NetTiers Documentation http://nettiers.com/DocumentationPage.
ashx
 Tlist Tips/Tricks http://community.codesmithtools.com/Co
deSmith_Community/b/nettiers/archive/2
006/03/09/10861.aspx


similar documents