3

I'm trying to map the response from an SP to corresponding models, custom for the specific SP. The SP uses column names that I don't want to see anywhere in my code because they're violating all standards (even bad spelling).

So, I tried creating a model like this one.

public sealed class Product
{
     [Column("Id_PRODUCT")]
     public int Id {get; set;}

     [Column("PruductTilte")]
     public string Title {get; set;}

     // Column Name = Description
     public string Description {get; set;}
}

And then in the partial Context

public partial class ContosoContext
{
    public async Task<Product[]> GetProductsAsync()
    {
         using (var cmd = Database.Connection.CreateCommand())
         {
             cmd.CommandText = "GeTpRoDuCtS";

             using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.CloseConnection))
             {
                 return ((IObjectContextAdapter)this)
                     .ObjectContext
                     .Translate<Product>(reader)
                     .ToArray();

                 // Actually calling reader.NextResult() and doing more translates here (multi-set response). 
             }
         }
    }
}

When executing this like var products = await new Context().GetProductsAsync() only Description is set, EF6 seems to be ignoring the ColumnAttribute.

Isn't this supposed to work? Is there any good work-around?

Mikael Dúi Bolinder
  • 2,080
  • 2
  • 19
  • 44
  • Workaround here https://stackoverflow.com/questions/39779270/dynamic-translate-to-avoid-c-sharp-syntax-errors/39798961#39798961 – Ivan Stoev Aug 13 '19 at 22:02
  • @IvanStoev jup, found that one before and many related question with different implementations of the custom data reader. Think I'll mark it as a duplicate of that one. – Mikael Dúi Bolinder Aug 13 '19 at 22:23

0 Answers0