Dapper. Map to SQL Column with spaces in column names

后端 未结 3 1286
灰色年华
灰色年华 2020-12-30 01:46

I\'ve managed to get something up and running today as small sandbox/POC project, but have seemed to bump my head on one issue...

Question:

3条回答
  •  死守一世寂寞
    2020-12-30 02:19

    There's a nuget package Dapper.FluentMap that allows you to add column name mappings (including spaces). It's similar to EntityFramework.

    // Entity class.
    public class Customer
    {
        public string Name { get; set; }
    }
    
    // Mapper class.
    public class CustomerMapper : EntityMap
    {
        public CustomerMapper()
        {
            Map(p => p.Name).ToColumn("Customer Name");
        }
    }
    
    // Initialise like so - 
    FluentMapper.Initialize(a => a.AddMap(new CustomerMapper()));
    

    see https://github.com/henkmollema/Dapper-FluentMap for more.

提交回复
热议问题