Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Missing AR

with 5 comments

Part of my new year resolution was to get rid off AR from my application architecture design replace it with pure NHibernate. But since AR had been my tool of choice for almost a year or so it just keep haunting me every now and then.

I believe the feature of AR that I am going to talk about is pretty old but somehow useful for certain situation; so let see.

Say you have to deal with User & User’s Roles scenario. A user can play many roles isn’t she? Now pretend you are a lazy developer / no because your DBA was lazy to create a Role, UserRoles table for you :) I know, I know I don’t think this will happen in the real world, your DBA can’t be that naughty :D but anyway one in a while if you were like me learn and love IPrincipal interface everytime I setup a User class you know that the IsInRole(string) will smile at you if it had to deal with Role stored as array of string.

[ActiveRecord]
public class User {

   [PrimaryKey]
   public virtual int Id { get; set; }

   [Property]
   public virtual string Name { get; set; }

   [Property]
   public virtual string[] Roles { get; set; }

}

No hack, No tweak simply sweet how can’t I miss the AR ;)

Advertisements

Written by Chorn Sokun

January 6, 2009 at 5:58 pm

5 Responses

Subscribe to comments with RSS.

  1. I have no much idea about coding but I know it makes the synergy when combined with business concept. Let’s take XBRL as example. More info on stockcam’s blog. You may have some ideas on this application or you may create another initiative one :-)

    stockcam

    January 11, 2009 at 5:21 pm

  2. Hmm, not sure what stockcam’s blog are all about?

    Chorn Sokun

    January 15, 2009 at 3:14 pm

  3. Why don’t you make a visit sometimes? Welcome you always and your comments will be appreciated :-)

    stockcam

    January 17, 2009 at 3:52 pm

  4. Allthough this has nothing to do with you post, I was wondering how you got those nice code embeddings?

    Serge

    serge desmedt

    February 7, 2009 at 2:42 am

    • use the
      sourcecode language=’csharp’
      …. whatever code you want to write …
      /sourcecode

      *note: PLACE sourcecode block inside [ … ]

      Chorn Sokun

      February 7, 2009 at 10:13 am


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: