Posts

Showing posts from June, 2011

Practical Example for Abstract Classes

using System; namespace AbstractClasses { public abstract class Messager { protected string _recipient; protected string _message; public Messager(string recipient, string message) { _recipient = recipient; _message = message; } public void ProcessMessage() { LogMessageLength(); // the code from here var isValid = false; if (ValidateRecipient()) { isValid = true; SendMessage(); } // to here will be implemented by the concrete classes if (isValid) NotifyTheServiceOwner("The message was correctly sent"); else NotifyTheServiceOwner("The message was NOT sent"); } protected abstract void SendMessage(); protected abstract bool ValidateRecipient(); private void LogMessageLength() ...

Table Per Hierarchy Inheritance with Column Discriminator and Associations used in Derived Entity Types

Image
In this article I will show how to model a table per hierarchy, a bit more complex than I found in books or other articles. I'm sure this model is present in real lif,e but I really didn't have the luck to find an example on the web when I needed it most. The complexity of this model is given by the Foreign Keys ( the Associations) which need to be placed in the derived entities types and the fact the discriminator depends on more than one column. The first problem I could fix, but the next one, with the discriminator based on two or three nullable columns I couldn't do it, unless if I use a single discriminator column (ie ItemType or something). The database is very simple. It is designed for an eshop which sells products, services and also has some nice packages, that combines products and services and offers them for good prices compared with if they would be bought alone. The products and services are very different in terms of how data describes them, so the decision ...

Working with TIME type in SQL and ASP .Net

Scenario: a teacher schedules his courses on a random different dates in the near future, but he always know the start time. For sample in the current week he can schedule a course for Tuesday and Friday, at 08:00 AM. In a database there would be the following tables: 1. course (title, summary, ..) 2. c ourse_schedule(course_id, location, start_time) where data about that schedule is preserved( ie. location) 3. course_schedule_span(schedule_id, course_date) for storing the dates when the schedule spans The dates have always the same start time, I knew this before designing the database, so in the first time I let the time in the course_schedule_span table, in course_date column (ie. 31/12/2011 16:00). Later the teacher wanted to set and the end time so I decided to move the start time into course_schedule table and this new end time field to add it there also. The first attempt was to store the time in a varchar(5) column, this would suffice for storing like hh:mm values. Later I ch...

About the "The Controls collection cannot be modified because the control contains code blocks" symptom

As the error message says, if a control contains code blocks (but not databinding expressions, ie <%# ..), its Controls collection can't be altered, by adding another control at runtime using Controls.Add. However, this rule doesn't apply for child controls, for example if a control uses other control with code blocks, then the first control's Controls collection (the parent's one) has no limitations. Usually this error is encountered mostly when working with the <head runat="server". Suppose there is a code block which uses some code to decide which protocol to use to download some external scripts, depending on the connection used by the client. <head runat="server"> <% if (!HttpContext.Current.Request.IsSecureConnection) { %> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script> <% } else {%> <script src="https://ajax.goo...