0

I have an application that stores data in database (oracle) I have simple model

public class FileTemplate
{
    public string Xml { get; set; }
    ...
}

and class map

public class FileTemplateMap : ClassMap<FileTemplate>
{
    public FileTemplateMap()
    {
        Table("FILE_TEMPLATE");
        Map(f => f.Xml, "XML").CustomSqlType("NCLOB");
        ...
    }
}

A want to add PostgreSql support. But PostgreSql doesn't have NCLOB data type. I modify my mapping:

    public class FileTemplateMap : ClassMap<FileTemplate>
    {
        public FileTemplateMap()
        {
            Table("FILE_TEMPLATE");
#if POSTGRE
            Map(f => f.Xml, "XML").CustomSqlType("TEXT");
#else
            Map(f => f.Xml, "XML").CustomSqlType("NCLOB");
#endif
        }
    }

Now I have to do different builds for oracle and postgresql with defining conditional compilation symbols (for postgresql). And application that build with POSTGRE compilation symbol doesn't work with oracle.

Are there other ways to do this without using conditional compilation symbols? I want to have one build, that works with both databases.

2 Answers 2

1

I'd do something like this

public static class CustomSqlTypeHelpers
{
    static readonly string _ClobSqlType;

    static CustomSqlTypeHelpers()
    {
        // Checks to validate config file setting ommitted
        _ClobSqlType = ConfigurationManager.AppSettings["ClobSqlType"];
    }

    public static PropertyPart LargeTextColumn(this PropertyPart pp)
    {
        return pp.CustomSqlType(_ClobSqlType);
    }
}

public FileTemplateMap()
{
    Table("FILE_TEMPLATE");
    Map(f => f.Xml, "XML").LargeTextColumn()
}
Sign up to request clarification or add additional context in comments.

Comments

0

I've done a little differently. Here is an article about my solution: http://beamyplum.blogspot.ru/2013/08/nhibernate.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.