My 1st CSLA WinForm App

Took me about 30 minutes. Following the example PT.

Here is how did I start:

1. Create 2 projects: Demo.Library, Demo.Library.Test.

2. Launch codeSmith, generate 2 BOs: for my situation, Trainee, TraineeList. (Haven’t figure out why do I need TraineeInfo)

3. Changed data access part of the generated code, the default is always SP. I am using inline SQL.

        private void ExecuteFetch(SqlConnection cn, Criteria criteria)

            using (SqlCommand cm = cn.CreateCommand())


                cm.CommandType = CommandType.Text;

                cm.CommandText = "SELECT * FROM [Training].[dbo].[Trainee_UV] WHERE [Trainee_ID] = @id";

                cm.Parameters.AddWithValue("@id", criteria.TraineeId);

                using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))




                    //load child object(s)





4. Create test case for DA of TraineeList BO. ( make sure app.config exists)

    public class ProjectListDATest



        public void ShouldGetTraineeList()


            TraineeList item = TraineeList.GetTraineeList();

            Assert.Greater(item.Count, 2800); // I knew there are more than 2800 trainees in db. 



5. Create WinApp project. Setup datagridview, bind datasource to TraineeList. ( I kind like this StrongType idea now, it’s so similar to our DataWindow.)

6. Add those plumping code in load event.

        private void Form1_Load(object sender, EventArgs e)




        private void DisplayList(TraineeList list)


            grdTrainees.DataSource = list;


Wow! It works!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s