Pregunta

I'm new to FluentNHibernate. I am working with AutoMapping. Let's say, I have a database which is generated by NHibernate. There's a table, named Document with 2 columns

  • Id: int
  • Description: nvarchar(255)

which is mapped to this class

public class Document
{
    public virtual int Id { get; set; }
    public virtual string Description{ get; set; }
}

I want to change data type of Description from nvarchar(255) to text in Database, so I created a console application as follow:

public class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Start process");           

        AutoMap.AssemblyOf<Document>().Override<Document>(y => y.Map(x => x.Description).CustomSqlType("text"));         

        Console.WriteLine("End process");
    }
}

There's no error, but nothing happened, the column Description is still nvarchar(255). I don't know what I am missing here. Any thought appreciated! Thanks

¿Fue útil?

Solución

SchemaUpdate can not alter columns only add it. However you could recreate (drop and create) it. Also if you set the length of a text field over a specific threshold (often 8k) then most Drivers will create the equivalent of "text" instead of "varchar".

var config = Fluently.Configure()
    .Database(...)
    .Mappings(m => m.Automapping.Add(AutoMap.AssemblyOf<Document>().Override<Document>(y => y.Map(x => x.Description).Length(20000)))
    .BuildConfiguration();

new SchemaExport(config).Create(true, true);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top