You are on page 1of 10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

How-To: Create Entities with Inertia in LASG


This walkthrough will get you started with the Inertia: Business Entity Component
Generator that is available in Layered Architecture Solution Guidance 2013
[http://visualstudiogallery.msdn.microsoft.com/caa8f808d4a54f48a88eda572834f37e]
.
The first step in creating layered applications after designing the database is to
create the entity classes. Before beginning this guide, please make sure that you
have completed the previous tutorial on Getting Started with LASG [http://serena
yeoh.blogspot.com/2014/02/lasggettingstarted.html] .
ThiswalkthroughalsousestheLeaveSampledatabase that is part of the Layered
ArchitectureSamplefor.NET [http://layersample.codeplex.com/] butyoumayuseyour
owndatabasetofollowthrough.

[./HowToCreateEntitieswithInertiainLASGFiredancerUnleashed!_files/01Guide.png]

1. InSolutionExplorer,expandtheTutorialsolution,gototheSharedfolder,right
clickontheTutorial.EntitiesprojectandclickAddEntities...

file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html

1/10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

[./HowToCreateEntitieswithInertiainLASGFiredancerUnleashed!_files/01
Launch.png]

2. TheInertia:BusinessEntityComponentGeneratorwilllaunch.Thecode
generatorisdividedinto3sections.

[./HowToCreateEntitieswithInertiainLASGFiredancerUnleashed!_files/01
Inertia.png]
file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html

2/10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

Tip:Noticethecodegeneratoriscolourcodedtothecodegenerationguide.
3. Atthe1.ChooseDataSourceandColumnssection,clicktheConnectbutton
toconnecttoaMicrosoftSQLServer.
4. IntheConnect...dialog,entertheServernameandselecttheappropriate
authenticationmethod.ClickConnecttoconnecttotheSQLserver.

[./HowToCreateEntitieswith
InertiainLASGFiredancerUnleashed!_files/01Connection.png]

Note:LASGusestheSQLServerManagementObjectsandtherefore,only
MicrosoftSQLServerissupported.YoucanuseanyeditionsofSQLServer
includingtheExpressedition.
5. SelecttheLeaveSampledatabasefromthedatabaselistlocatedbesidethe
Connectbutton.
6. IntheSourcetab,selecttheLeavestablefromtheSourcesdropdownlist.Allits
columnswillbelistedinthelistboxbelowtheColumnscheckbox.
Tip:Inertiawillattempttosuggesttheentityclassnameforyoubasedonthe
selectedtablesname.Ifyourtableshavepluralnames,theSingularizeclass
namesoptionwillattempttosuggestsingularentityclassnamesforyou.
7. IfyouarenotusingtheLeaveSampledatabasetablesandhaveabbreviated
columnnamesi.e.hr_wkflowID,PrdName,StdMercNameetc.,youcancreate
meaningfulpropertynamesforthembyclickingonthebarabovethecolumnlist.
ThislaunchestheDefineColumnMappingsdialog.Makeanynecessary
changestothePropertyNameandclickOKwhendone.

file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html

3/10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

[./HowToCreate
EntitieswithInertiainLASGFiredancerUnleashed!_files/01DefineMap.png]

Note:Itisrecommendedthatyouhavewelldefinedmeaningfulcolumnnames
inthetablesthantorelyonthecolumnmappings.
8. CheckontheColumnscheckboxtoselectallthecolumnsandclickonthe
[./HowToCreateEntitieswithInertiainLASGFiredancerUnleashed!_files/01Right
Button.png] buttontoaddthemtothe2.DefineEntitySettingssection.

file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html

4/10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

[./HowToCreateEntitieswithInertiainLASGFiredancerUnleashed!_files/01
Selected.png]

Tip:Youcanalsoindividuallyselectordeselectcolumns.PresstheCtrlkey
whileclickingonthecolumnstoselect/deselectindividualcolumnsorusethe
Shiftkeytoselect/deselectarangeofadjacentcolumns.
Note:Notalldatatypesaresupported.Complexdatatypesarecurrentlynot
supported.
9. TheReferenceTotabwillshowallthetablesthatthecurrenttableisreferencing
towithaforeignkey.Youcanchoosetorelatetotheentiretableasareference
objectorindividuallyselectthecolumnswhichyouwanttoincludeaspartofthe
currententity(a.k.a.borrowedcolumns).Onceyouaredonewithyour
selections,clickonthe [./HowToCreateEntitieswithInertiainLASGFiredancer
Unleashed!_files/01RightButton.png] buttontoaddthemtotheEntity
propertiesgrid.Forsimplicity,weshallnotaddanythingfromhereinthistutorial.
10. TheReferenceBytabshowsallthetablesthatisreferencingthecurrenttable
withaforeignkey.Youcanchoosetorelatethetableshereasacollectionof
Entities.Clickonthe [./HowToCreateEntitieswithInertiainLASGFiredancer
Unleashed!_files/01RightButton.png] buttontoaddthemtotheEntity
propertiesgrid.YouwillalsoneedtogeneratetheEntityclassesindividuallyfor
thetablesyouselectedherelater.Forsimplicity,weshallnotaddanythingfrom
hereinthistutorial.
11. ThecolumnsthatyouchoosewillappearintheEntitypropertiesgridunderthe
2.DefineEntitySettingssectionaspropertiestobegeneratedfortheEntity.
Youcanmakeadjustmentsherei.e.changingthecommentsormarkinga
file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html

5/10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

propertytoacceptnulls.
Tip:Incaseyouwanttoremoveanycolumnsfromthepropertieslist,justselect
therowandpresstheDeletekeyonthekeyboardoryourcanrightclickonthe
selectedrowtoinvokeacontextmenutodeleteit.
12. Onceyouareready,clickontheAddtoCodeGenerationbuttontoqueuethe
definitiontothe3.GenerateEntitiessection.Youcanqueueasmanyentities
forcodegenerationasyouwish.Tocreateanotherentity,simplyclickonthe
Newbutton.Forthistutorial,weshallcreate2entitiesLeaveand
LeaveStatusLog.
13. Eachqueuedentitydefinitionwillbelistedinthe3.GenerateEntitiessection.
Youcanreviewthedefinitionsandmakeanylastmomentchangesinthe
propertygridlocatedatthebottomofthesection.Youcandeleteanyentity
propertiesbyselectingtherowandpressingtheDeletekey.

file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html

6/10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

[./HowToCreateEntitieswith
InertiainLASGFiredancerUnleashed!_files/01Generate.png]

Caution!Tamperingwiththepropertiesinthepropertygridmaycause
unexpectedresultsorerrorsincodegeneration.Makesureyouunderstand
thebehaviourofthecodegeneratorbeforemessingwiththevaluesinthe
propertygrid.
14. Youcanperformvariousactionfromthetoolbaratthe3.GenerateEntities
section.YoucanPreviewthecodethatwillbegenerated,setOptions,reposition
theproperties,Resetthedefinitionssothattheywillbecodegeneratedagainor
Deletethedefinitions.

file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html

7/10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

[./HowToCreateEntities
withInertiainLASGFiredancerUnleashed!_files/01Toolbar.png]

Warning!Deleteddefinitionswillnotberecoverable.
Note:Alldefinitionswillbemarkedascodegenerated(indicatedbythe
IsUpdatedproperty)aftercodegeneration.Theywillcontinuetoappearinthe
listbutwillnotbecodegeneratedthenexttime.ClickingResetwillchangeone
ormoredefinitions'IsUpdatedvaluetotrueandmarkthemforcodegeneration
again.
YoucanalsoDeleteanentityproperty,anentitydefinitionorallentitydefinitions
fromthetoolbar.ClickingontheOptionsiconwillopentheCodeGeneration
Optionsdialogthatwillallowyoutosetafewstandardoptions.Leavethe
settingsaloneandclickOK.

[./HowToCreateEntitieswithInertiain
LASGFiredancerUnleashed!_files/01Options.png]

15. Finally,clicktheGeneratebuttontogeneratetheentityclasses.
16. AttheCodeGenerationCompleteddialog,clickOK.
17. TheTutorial.Entitiesprojectshouldcontainthegeneratedcodefilesforthe
entities.

file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html

8/10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

[./HowToCreateEntities
withInertiainLASGFiredancerUnleashed!_files/01Project.png]

Summary
WehavebasicallygonethroughhowtousetheInertia:BusinessEntityComponent
Generator to create Entity classes for our layered application. You can make any
necessarychangestothecodebuttakenotethatanychangesmadeinyourcode
will not be reflected in the definitions stored in Inertia. Therefore, practice caution
whenyouareregeneratingcodeonexistingcodefile.
Coming up next HowTo: Create Data Access Components with Momentum in
LASG[http://serenayeoh.blogspot.com/2014/03/lasgcreatingdataaccesscomponents.html]
.
Posted5thMarchbySerenaYeoh
Labels:.NET,3tier,C#,DeveloperCommunity,LASG,LayeredArchitecture
0 Addacomment

Enteryourcomment...

Commentas:

greg_dorian(Google)

Signout

Publish

Preview

Notifyme

file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html

9/10

15/10/2015

HowTo:CreateEntitieswithInertiainLASG|FiredancerUnleashed!

file:///C:/Users/greg/Desktop/layered/HowTo%20%20Create%20Entities%20with%20Inertia%20in%20LASG%20%20%20Firedancer%20Unleashed!.html 10/10

You might also like