NHibernate 3 specify sql data type with loquacious syntax

后端 未结 2 1810
眼角桃花
眼角桃花 2021-01-21 08:55

I\'m trying to map an Entity with a string property to a varchar column in NHibernate 3 using the new Loquacious API but I can\'t figure out how to specify the Type to

相关标签:
2条回答
  • 2021-01-21 09:29

    An answer to the question itself ("specify sql type") would be to define the property like this:

    ca.Property(x => x.Code, map =>
            {
                map.Column(cm => {
                    cm.Name("EnityCode"); 
                    cm.NotNullable(true);
                    cm.SqlType("varchar");
                }); 
            });
    

    Directly specifying the SQL type should be considered a hack which is not necessary here, though. It's preferable to use the map.Type(NHibernateUtil.AnsiString); solution and have NHibernate deduce the SQL type.

    0 讨论(0)
  • 2021-01-21 09:31
    ca.Property(x => x.Code, map =>
    {
        map.Type(NHibernateUtil.AnsiString);
        map.Column(/*etc.*/); 
    });
    
    0 讨论(0)
提交回复
热议问题