Learn More





DNN Community Blog

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.

Creating the Task Class

In the previous blog entry we went into our SQL Database and created a table to hold our tasks data. Now we need to move back into Visual Studio so that we can create a “class” within our module project. This “class” will serve as a definition for the objects that will represent tasks within our module’s code. You could also think of each task object correlating with one row (a task) in our “Tasks” table in our SQL Server database.

If you’ve got knowledge of OOP (Object Oriented Programming) this information is probably not new to you. Though, if you don’t have a background in OOP hopefully this blog will help you understand some of the concepts and I’ll provide some helpful links to OOP resources at the bottom. Also, as you get more into code you will pick it up faster than you think so stick with it even if things get a little fuzzy!

So we’re storing tasks in the database and we need to represent these tasks as “objects” before we send them to the database to get stored.

Task Objects

Classes & Objects
To actually create the class in code isn’t that difficult, but to understand what’s going on is the main point here. Classes provide the definition of our objects. That is a class defines the properties & functions that our objects have. In our case, the same data points that we hope to capture and save to SQL will be properties of the objects that will exist in memory before being sent to the database. Likewise when we retrieve data from the database we will create new objects and populate their properties with the data that comes back from SQL. So, to be repetitive for good measure, the term “class” is the definition or blue print for our objects. Whenever we create a new task object it will be created with the properties and functions that the object’s blue print (its class) has defined.

Creating the Task Class
To create a new class in Visual Studio we simply right click on our module project and select “Add” then “Class”. Side note: there are classes for nearly everything so get comfortable with these concepts and don’t worry if your module has dozens of classes.

Let’s create the “Tasks” class in Visual Studio. If you take a step back and think about organization, since there are (or can be) lots of classes, we should probably create a folder to store these files. So before we even create a class let’s create a new folder so that we can store these classes in an organized manner and keep things tidy. To do this just right click on the project and choose “Add” then “New Folder”. Now we need to name the folder and in other tutorials online I’ve seen them named a lot of different things like “ojbects”, “models”, “classes”, ”repository”, etc.  You can name the folder whatever you like I’m just giving you this information in case you download a module from the forge and see various folder names that hold all these class files.

Create a folder in Visual Studio

I’m going to name the folder “models”, but you can name it whatever you would like. Create a folder and once you create the folder then right click on the folder and click “Add” then “Class”. Then give the class name the name of “Task.cs”. Congratulations, you’ve just created your first class! Now the class currently doesn’t have any functionality, but nevertheless it is a class. As you would imagine we now need to add in the properties of our task class. So we need to add the same data points that we are capturing in SQL to our class as properties. Your class should look similar to the following:

The Task Class definition

Public & Get; Set;
As I’ve mentioned in the video below the class consists of a few items that may look odd to you if you don’t have a strong OOP background. The terms “public” and then that “get; set;” thing may throw you for a loop. I’ve included some specific links below about class modifiers, properties, accessors, and auto-implemented accessors that will help you understand more.

Now that we’ve created our class we are ready to create task objects for use in our module and we are getting close to being able to actually retrieve some tasks from the database and show them through our module, but we have a few more steps left. So hang in there because we are indeed making progress.

OOP Helpful Links:

Go to the Next Blog Entry: Creating the GetTasks Stored Procedure


mohammad azarbara
mohammad azarbara Monday, November 03, 2014 7:03 AM (link)
James Brown
Link to the series introduction

Link to the previous Blog Entry:
James Brown Monday, June 15, 2015 11:40 AM (link)

Comment Form

Only registered users may post comments.


2sic Daniel Mettler (125)
Aderson Oliveira (15)
Alec Whittington (11)
Alex Shirley (10)
Andrew Nurse (30)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (22)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (203)
Chris Paterra (55)
Clinton Patterson (28)
Cuong Dang (21)
Daniel Bartholomew (2)
Dave Buckner (2)
David Poindexter (3)
David Rodriguez (2)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (74)
Geoff Barlow (6)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (270)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matthias Schlomann (15)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Mike Horton (19)
Mitchel Sellers (28)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Peter Donker (52)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott S (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Timo Breumelhof (24)
Tony Henrich (3)
Torsten Weggen (2)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (37)
Will Strohl (163)
William Severance (5)
Try Evoq
For Free
Start Free Trial
a Demo
See Evoq Live
Need More Information?