hotrannam's corner

WCF Serialization

leave a comment »

Written by hotrannam

August 11, 2009 at 3:33 pm

Posted in WCF

Tagged with

Bill Gates, 1984

leave a comment »

“To create a new standard, it takes something that’s not just a little bit different, it takes something that’s really new and really captures people’s imagination and the Macintosh, of all the machines I’ve ever seen, is the only one that meets that standard.”

Microsoft founder Bill Gates, 1984

Written by hotrannam

July 12, 2009 at 3:42 pm

Posted in Uncategorized

Mapping simple IDictionary with fluent NHibernate

leave a comment »

Database schema

image

Domain entity

public class Issue : EntityBase

{

    public Issue()

    {

        this.CustomFields = new Dictionary<string, string>();

    }

 

    // other properties

 

    public virtual IDictionary<string, string> CustomFields

    {

        get;

        set;

    }

}

Fluent mapping

public class IssueMap : ClassMap<Issue>

{

    public IssueMap()

    {

        Id(x => x.Id).GeneratedBy.Guid();

 

        // other mappings

 

        HasMany(x => x.CustomFields)

            .WithTableName("IssueMetadataValue")

            .KeyColumnNames.Add("IssueId")

            .Cascade.All()

            .AsMap<string>(

                index => index.WithColumn("Name").WithType<string>(),

                element => element.WithColumn("Value").WithType<string>()

            );

    }

}

Written by hotrannam

June 11, 2009 at 11:05 pm

Posted in ALT.NET

Tagged with ,

Create NHibernate session factory with fluent mappings

leave a comment »

Fluent NHibernate introduces ClassMap to replace HBM mapping files and these mappings must be located in the creation of NHibernate session factory. HBM mappings are built as resources of an assembly being specified in configuration file. Fluent NHibernate also requires an assembly containing fluent mappings.

public static ISessionFactory CreateSessionFactory()

{

    var sessionFactory = Fluently.Configure()

           .Database(

                MsSqlConfiguration.MsSql2005.ConnectionString(

                    c => c.Is(System.Configuration.ConfigurationManager

                        .ConnectionStrings["DolphinConnection"].ConnectionString)

                )

            )

           .Mappings(

                m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())

            )

           .BuildSessionFactory();

 

    return sessionFactory;

}

Assembly.GetExecutingAssembly() returns executing assembly where fluent mappings are defined within.

Written by hotrannam

June 10, 2009 at 9:57 pm

Posted in ALT.NET

Tagged with ,

I am back

leave a comment »

I decide to go back and keep blogging after a long time.

Written by hotrannam

June 9, 2009 at 3:57 pm

Posted in Uncategorized