Wiki

Clone wiki

Boot.Multitenancy / Classmapping

nHibernate/FluentnHibernate mapper

This section descibes how to map your class as a object in a database.

This class will create a table Category with from each property. See below. Inherit the interface IEntity from Boot.Multitenancy.Intrastructure.Domain namespace and each class that inherit IEntity will be created in database.

#!c#
using Boot.Multitenancy.Intrastructure.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BootProject.Apps.Catalog.Models
{
    public class Category : IEntity
    {
        public virtual Int32 Id { get; set; }
        public virtual Int32 ParentId { get; set; }
        public virtual string Title { get; set; }
        public virtual string MetaTitle { get; set; }

    }

    public class CategoryMap : Entity<Category>
    {
        public CategoryMap()
        {
            Id(x => x.Id)
               .Unique()
               .Column("Id")
               .Not.Nullable()
               .GeneratedBy.Identity()
               .CustomType<Int32>();
            Map(p => p.Title);
            Map(p => p.ParentId);
            Map(p => p.MetaTitle);
        }
    }

Map as hierarchy Entity

Used for map as a node.

#!c#
    public class SiteNode : Node, IEntity
    {
        public virtual string Title { get; set; }
        public virtual string MetaTitle { get; set; }

    }

    public class SiteNodeMap : Entity<SiteNode>
    {
        public SiteMap()
        {
            Id(x => x.Id)
               .Unique()
               .Column("Id")
               .Not.Nullable()
               .GeneratedBy.Identity()
               .CustomType<Int32>();
            Map(p => p.Title);
            Map(p => p.ParentId);
            Map(p => p.MetaTitle);
        }
    }
   }

Updated