Alt.net Beers #5 – 12th of January (yes, I know it’s next Monday…)

With all the festive excitements, I really thought I had announced this when I put the date down on http://ukdotnet.ning.com but I obviously didn’t.

So as (nearly) every months, we’ll be holding our monthly alt.net meeting in Soho next Monday, with tester extraordinaire and dynamic language addict Ben Hall. Please register on http://ukdotnet.ning.com/events/altnet-london-beers-5 so I know how many of you to expect. We also usually wait for everyone to have arrived before starting, and if you’re not on the list we can’t start!

The format is a mini openconf-style session. Here are the rules, slightly changed to learn from the previous event.

  • Arrivals, discussion and socializing between 18:00 and 19:15, with one necessity: find the topic of the day and find the questions that we will try to answer.
  • Between 19:15 and 19:30 we will vote on the subject we want to talk about, in two rounds, by raising hands.
  • At 19:30 the big clock will start ticking for a time-boxed 60 minutes workshop on the subject. The goal is simple: can we as a group get insight and progress our understanding of the problem
  • If the subject stales, the subject can switch to a new one, the second down in the list of votes.
  • At 20:30 the clock will ring and that will be it of the conversation. We’ll do a roundtable of each person where I’ll be asking you to decide of an action you’re going to take based on the discussion (something new we didn’t do until now).
  • Then everyone will write it down for wiki publication, everybody will be able to continue the discussion in the pub or wherever they see fit.

The location

We should be able to hold our reunion at the Tequilla lounge bar, like last time. I’ll have confirmation tomorrow, and if not I’ll announce here a new location.

Ads

Fluent-nhibernate and nvarchar(max)

As you may know, text and ntext types are being depreciated in sql server 2005+, and replaced by varchar(max) and nvarchar(max).

If like me you rely on nhibernate to generate your database, the trick for getting nvarchar(max) is to set the length of the field to 10000. I wrote a small extension method to do this.

    public static class PropertyMapExtensions

    {

        public static PropertyMap WithMaxSize(this PropertyMap map)

        {

            return map.WithLengthOf(10000);

        }

    }

I use the automapping functionality, so this is what it then looks like.

            AutoPersistenceModel.MapEntitiesFromAssemblyOf<Movie>()

                .Where(t => t.Namespace == (typeof(Entity).Namespace) && !t.IsAbstract && t.IsPublic)

 

                .ForTypesThatDeriveFrom<Movie>(x =>

                {

                    x.Map(m => m.LongSynopsis).WithMaxSize();

                    x.Map(m => m.Notes).WithMaxSize();

                })

                .Configure(configuration);

And if you’re interested in all things fluent-nhibernate, why not come and listen to my talk about it on the 22nd of January at SkillsMatter?

Ads

Using extension methods on null objects

One feature that is often disregarded in extension methods is that they get called for null objects. While instrumenting parts of OpenRasta, I faced the problem of having some classes not always created through the container. As such, sometimes their Log property would be null, and each call to a logging method would have to check for that condition. After doing a few back-and-forth, I settled on using an extension method, coupled with a null object.

Take a simple class, and add a Log property.

public class LoggingClass

{

    public ILogger Log { get; set; }

}

Then, create a simple extension method on the ILogger, and return a null object

        public static ILogger Safe(this ILogger logger)

        {

            if (logger == null)

                return NullLogger.Instance;

            else

                return logger;

        }

Now all the logging code can simply call the Safe() method to ensure that, in the absence of a logger, a null object will be used instead. The code using it looks like the following.

        public void DoSomething()

        {

            Log.Safe().WriteDebug("I did something!");

        }

Voila!

Ads