DapperLib / DapperAOT

Build time tools in the flavor of Dapper
Other
349 stars 19 forks source link

feat: support [Column] #85

Closed DeagleGross closed 7 months ago

DeagleGross commented 8 months ago

Goal:

Support [System.ComponentModel.DataAnnotations.Schema.ColumnAttribute] as an additional way to override parameter name. Requested by some users (stackoverflow)

Example:

To make override work, one need to specify both [Column] and [UseColumnAttribute] attributes, for example:

class MyType
{
    [UseColumnAttribute]
    [Column("myOtherName")]
    public string Name { get; set; }
}

Rules:

  1. If [Column] and either [UseColumnAttribute] or [UseColumnAttribute(true)] is defined, than override will work
  2. If [UseColumnAttribute(false)] is explicitly specified, then overriding will not happen
  3. If [Column] is specified, but [UseColumnAttribute] is missing, then DAP043 will be emitted to the user: "Attach the [UseColumnAttribute] attribute to make Dapper consider [Column]"
  4. If 1) is followed, but also [DbValue] with property Name is specified, then a warning message will be emitted to the user: DAP042 "A column name is specified via both [DbValue] and [Column]; '' will be used"

Closes #36

mgravell commented 8 months ago

looking good; fixed some minor nits:

an open question on the new attribute, but: looking good!

DeagleGross commented 8 months ago

looking good; fixed some minor nits:

  • avoid /en-us/ in docs links; if you cut it, it will use the user's locale settings
  • formatting in docs
  • used a different variant of that string equality fix

an open question on the new attribute, but: looking good!

Thanks for the useful advices and fixes, Marc! Sorry for attribute usage - I added it. Ready for review