Fluent NHibernate Column Mapping with Reserved Word

前端 未结 3 1210
悲&欢浪女
悲&欢浪女 2020-12-11 15:03

I\'ve read that using a back tick ` should allow for using of reserved words. I\'m using SQL Server and Fluent NHibernate and have a column name \"File\". If I map it wi

相关标签:
3条回答
  • 2020-12-11 15:28

    There are non manual configuration options for this as covered here: NHibernate: forcing square brackets in schema export?

    as well as an alternative: Fluent NHibernate and PostgreSQL, SchemaMetadataUpdater.QuoteTableAndColumns - System.NotSupportedException: Specified method is not supported

    E.g. SchemaMetadataUpdater.QuoteTableAndColumns(cfg) which in FluentNhibernate would look something like

    var config = Fluently.Configure()
       ...
       ...
       .ExposeConfiguration(cfg => SchemaMetadataUpdater.QuoteTableAndColumns);
    
    0 讨论(0)
  • 2020-12-11 15:33

    To be perfectly clear, the exact syntax would be

    Map(x => x.File).Column("`File`");
    
    0 讨论(0)
  • 2020-12-11 15:38

    You need to put ` on both sides, like this:

    "`File`"
    

    As @Astaar says, the full syntax is:

    Map(x => x.File).Column("`File`");
    
    0 讨论(0)
提交回复
热议问题