简体   繁体   中英

Get view using Entity Framework

I have a SQL database view which I want to define a code for it in Entity Framework. The view is going to be shown in my web page.

The thing is that I am not sure if I will like to add some more columns in the future to the DB view. These columns are not identified now and I do not know currently what they will be (if I will add them).

I want to allow flexibility to add columns to DB view and that the view in my web page will change accordingly to the DB view.

For this change I do not want to change the dlls in the Entity Framework side (not again generate the objects from the new view and publish again).

Any ideas on a good way for doing it ?

Thanks

Since Entity Framework is an Object Relational Mapping technology I don't think it is a good use case for it because you don't want to have to keep the mapping in sync and I can't see much benefit of the entity for what you are doing.

I would just use raw DataReaders. With a DataReader you can just do Select * From MyView as the SQL and then use the GetSchemaTable method to identify what columns are present at runtime and loop round them etc. keeping it flexible as the view changes. (Link based on Sql Server SqlDataReader but you can adjust for your specific Database provider).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM