0

I tried calling ObjectContext.Translate<T> where T is the abstract base type of a table-per-hierarchy entity. If the DbDataReader is streaming back all the columns of the underlying table, I thought this method would be able to construct the approprate subtype for it by reading the discriminator column, but instead it throws an exception saying it can't instantiate the abstract base type. If it was properly functioning, it would be trying to construct the derived discriminated type rather than the base type.

Is this a bug in the method, or is there some other way to read back table-per-hierarchy types from a data reader? I need to return table-per-hierarchy entities from a stored procedure (particularly one with multiple active result sets), and I can't seem to find an appropriate method that can translate the results while observing the data model mappings and table per hierarchy types.

Triynko
  • 18,766
  • 21
  • 107
  • 173
  • This is really not promising: https://msdn.microsoft.com/en-us/data/jj691402/ "Note: EF does not take any mapping into account when it creates entities using the Translate method. It will simply match column names in the result set with property names on your classes." How can the method claim it loads entities, when it cannot even map the column names onto the entity correctly, let alone read the discriminator and instantiate the right derived type in a table-per-hierarchy entity? – Triynko Apr 25 '18 at 05:28
  • Another person said: "Now I am forced to rename my db columns to my model (or vice-versa) so that they match in order for the ExecuteStoreQuery (or Translate) to materialize my entities, which in my opinion it's terrible." https://social.msdn.microsoft.com/Forums/vstudio/en-US/b7630f85-0ef0-4d06-8633-70faa2849583/objectcontexttranslatet-and-executestorequeryt-materialization-issues?forum=adodotnetentityframework – Triynko Apr 25 '18 at 05:29

0 Answers0