Getting Dapper to return an empty string instead of a null string

前端 未结 4 563
难免孤独
难免孤独 2021-01-18 13:13

I know it\'s kind of the wrong thing to do, but I\'m dealing with a legacy codebase that has NULLS when it means empty strings and vice versa.

I can\'t immediately

4条回答
  •  伪装坚强ぢ
    2021-01-18 13:50

    You can control this with your queries, for example:

        public class Data
        {
            public string Foo { get; set; }
        }
    
        var result = conn.Query("select Foo = coalesce(Foo, '') from MyTable");
    

    So in the above example, coalesce will return an empty string when Foo is null.

提交回复
热议问题