title: Dapper.NET mapping with Data Annotations
body: <p>So I have a class with a property like this:</p>
  
  <pre><code>public class Foo
  {
    [Column("GBBRSH")
    public static string Gibberish { get; set;}
    ....
  }
  </code></pre>
  
  <p>For saving data, I have it configured so that the update/insert statements use a custom function:</p>
  
  <pre><code>public static string GetTableColumnName(PropertyInfo property)
  {
    var type = typeof(ColumnAttribute);
    var prop = property.GetCustomAttributes(type, false);
  
    if (propr.Count() &gt; 0)
      return ((ColumnAttribute)prop.First()).Name;
    return property.Name;
  }
  </code></pre>
  
  <p>This handles fine, but I noticed that when I go to retrieve the data, it isn't actually pulling data back via the function for this particular column. I noticed that the other data present was pulled, but the column in question was the only field with data that didn't retrieve.</p>
  
  <p>1)  Is there a way to perhaps use the GetTableColumnName function for the retrieval part of Dapper?</p>
  
  <p>2)  Is there a way to force Dapper.NET to throw an exception if a scenario like this happens? I really don't want to have a false sense of security that everything is working as expected when it actually isn't (I get that I'm using mapping that Dapper.NET doesn't use by default, but I do want to set it up in that manner).</p>
  
  <p>edit:</p>
  
  <p>I'm looking in the SqlMapper source of Dapper and found:</p>
  
  <pre><code> private static IEnumerable&lt;T&gt; QueryInternal&lt;T&gt;(params) // my knowledge of generics is limited, but how does this work without a where T : object?
   {
     ...
     while (reader.Read())
     {
       yield return (T)func(reader);
     }
     ...
   }
  </code></pre>
  
  <p>so I learned about two things after finding this. Read up on Func and read up on yield (never used either before). My guess is that I need to pass reader.Read() to another function (that checks against column headers and inserts into objects appropriately) and yield return that?</p>