How can I retrieve data from a dynamic table with new columns using Entity Framework without modifying the model?

Juan Bohorquez 0 Reputation points
2025-01-17T14:13:31.57+00:00

Let's imagine we have a table in the database where, through the client interface, it is possible to add columns dynamically using ADO. In the backend, I am using the Entity Framework (EF) to query on this database. However, the model in my code is fixed and does not reflect these additional dynamic columns that are added to the table.

Since the additional columns are not defined in my EF model, when EF tries to build the query, it launches an exception because the new columns are not registered in the model. This happens because EF expects the model properties to match the table columns in the database.

How could you handle this situation in order to get those new additional fields without constantly modifying the model in the code? In other words, how can I recover these dynamic data from EF if the new columns are not registered in the model, considering that in a production environment you do not want to constantly modify the EF scheme?

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
771 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 69,501 Reputation points
    2025-01-17T16:56:49.8166667+00:00

    EF is not a good fit. the point of EF is to map queries to strongly typed objects. even dynamic queries in EF are designed to return a strongly typed object.

    if you can not update the entity classes, then stick with ado.net and its recordsets which are dynamic.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.