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?