Try fast search NHibernate

02 September 2009

Learning some .NET new concepts

In the last “Alt.NET Hispano café” I have learned some new concepts.

Assertions: “The framework I like have all those things solved”; “The framework I like is an example of how encapsulate the complexity”

This is how look a property get-set using that framework:

private static PropertyInfo<string> NameProperty =
RegisterProperty<string>(p=>p.Name, "Project name");
public string Name
get { return GetProperty(NameProperty); }
set { SetProperty(NameProperty, value); }

private static PropertyInfo<SmartDate> StartedProperty =
public string Started
get { return GetPropertyConvert<SmartDate, string>(StartedProperty); }
set { SetPropertyConvert<SmartDate, string>(StartedProperty, value); }

Note the Started property is a “special” DateTime.

The follow is how look the fetch by ID:

private void DataPortal_Fetch(SingleCriteria<Project, Guid> criteria)
using (var ctx =
// get project data
var data = (from p in ctx.DataContext.Projects
where p.Id == criteria.Value
select p).Single();
LoadProperty(IdProperty, data.Id);
LoadProperty(NameProperty, data.Name);
LoadPropertyConvert<SmartDate, System.DateTime?>(
StartedProperty, data.Started);
LoadPropertyConvert<SmartDate, System.DateTime?>(
EndedProperty, data.Ended);
LoadProperty(DescriptionProperty, data.Description);
_timestamp = data.LastChanged.ToArray();

// get child data

My personal response to the assertion is : the framework you like may have “all things solved” but somebody, or something, should write that plumbing code for me; about the “encapsulation of complexity” perhaps you are talking about some other kind of complexity because I can't see where is the “encapsulation”.

Assertion: “What you are doing is only for genius/aliens”

What the altnetter guy, that obviously is not the same of the assertions, was showing was:

public class Track : Entity
public virtual string Name { get; set; }
public virtual Album Album { get; set; }
public virtual MediaType MediaType { get; set; }
public virtual Genre Genre { get; set; }
public virtual string Composer { get; set; }
public virtual int Milliseconds { get; set; }
public virtual int Bytes { get; set; }
public virtual decimal UnitPrice { get; set; }

The follow is how look the fetch by ID:

public T Get(object id)
return Session.Get<T>(id);

Note: the code is a generic implementation that mean that even in presence of a parent-child relationship or anything else the line to execute is the same.

My personal response to the assertion is: if how we are working is understandable only by genius/alien I must talk with my mother (perhaps “The Visitors” was not only a TV fiction).


  1. EXCELLENT post.. Thank you for clarify.

    I've learned about the meaning of "encapsulation" for earthmen.. For the other hand I started to have certain doubts about the identity of my father.

  2. The goggles! they do nothing!... hehe, it really hurts to look at that first chunk of code

  3. Maestro, gracias por compartir tus conocimientos y las criticas constructivas,se respeta y más aun de quien vienen.

    He escrito uno apreciación en mi blog te envito a verla.