Archive, C#, NHibernate

NHibernate Formula Properties

Jason / February 19, 2008

One often overlooked feature of NHibernate is the use of formula properties. Formula properties are properties that do not map to columns in the database, but instead are mapped using raw SQL queries.

The formula is mapped in the NHibernate mapping file using the same property element that normal properties use, just replacing the column keyword for the formula keyword.

<property name="FormulaPropertyName" formula="SQL STATEMENT" /> 

The basic idea is that when NHibernate loads your object it will issue your custom SQL at the same time, allowing for complex read-only properties to offload their work to the database.

For example, assume you have an class representing an order on an e-commerce website. An order is typically composed of line items, and a common question to ask the order as a whole is “what is your subtotal?”. Without weighing the pros and cons of such a decision assume that you do not want to store the subtotal as a field on the order table.

A perfectly acceptable solution would be to have a read-only property as such:

public decimal SubTotal{ get{ decimal subTotal = 0; foreach(LineItem li in this.LineItems){ subTotal += li.ExtendedPrice; //i.e., units ordered times unit price. } return subTotal; } } read more

Archive, ASP.NET

Comments In ASP.NET

Jason / December 22, 2007

Comments in HTML come in handy to temporarily remove site content. As ASP.NET developers, we have HTML comments available to use. In any ASPX markup file you can simply use the comment notation. read more

Archive, ASP.NET

Runat Server

Jason / December 20, 2007

As an ASP.NET developer you have undoubtedly seen controls with their runat property set to the value server. Other than being a required property, what does that property really mean? read more

Archive, ASP.NET

Validating Drop Downs In ASP.NET – Part 1

Jason / December 19, 2007

User input validation is an important component in any user interface. In the realm of web development a response UI is extremely important to the users experience.

If you are like myself, programming in JavaScript does not come easily to you. Fortunately, ASP.NET contains several validator controls that allow for client side form validation without you having to program any JavaScript.

Take for example a simple drop down control.

<asp:DropDownList ID="ddlSampleDropDown" runat="server"> <asp:ListItem Value="">--please select one--</asp:ListItem> <asp:ListItem Value="1">Apples</asp:ListItem> <asp:ListItem Value="2">oranges</asp:ListItem> </asp:DropDownList> read more