How to map an identity column, that has a different name, with Dapper?

前端 未结 1 477
时光取名叫无心
时光取名叫无心 2021-01-12 17:31

I have a database with id columns like BookId, AuthorId, etc. My code files, however, just have an Id property. I\'m attempting to convert parts of the program that use NH

相关标签:
1条回答
  • 2021-01-12 18:25

    By design, dapper does not have a mapping layer. One step down that road, and before we know what has happened all of a sudden we'll be drowning in configuration files. So: two options:

    • add an alias in the SQL
    • add a shim in the C#

    so either (sql):

    select BookId as [Id], Name from Books
    

    or (C#):

    private int BookId { get { return Id; } set { Id = value; } } // just for dapper
    
    0 讨论(0)
提交回复
热议问题