Entity Framework map some properties

1

I have a sqlserver database from which I generate the corresponding models with EF. The problem arises because a table in the database for example users is dynamic, it may be that a record appears or not (Address).

TABLE USERS with records: ID, First Name, Last Name but Address may not appear in the table.

The problem comes in mapping the User object with its corresponding properties ID, First Name, Last Name, Address. Let's see if there is any method that maps the property "address" in the case that exists in the table, but creates the user object without the property address. Is it necessary for the model to have all the properties equal to the records in the table?

EDIT : What really happens to me is that a server can have different versions of a project from a database. In the first version the address is not defined, it may be that in another server it has a new version of the project and it is in the table. Then I have an api that the client decides in which server to connect there, the problem arises that the client does not know which version connects the project but I have to generate the client model depending on whether the column is in the database or not

    
asked by user2742460 20.07.2016 в 16:19
source

1 answer

1

The truth that you propose does not make much sense, whether you define it or not define it, then if it is an optional data you could make it null and void.

The mapping of EF can not be dynamic because it is assumed that the structure of the db is fixed and defined by the schema of the db

I outline, if the value of the columan is optional, define it to allow nulls, then you will not need to assign it if you do not have that info for a sura

    
answered by 23.07.2016 в 07:57