Last post Aug 08, 2015 11:31 AM by kmcnet
Aug 04, 2015 12:00 PM|kmcnet|LINK
Hello everyone and thanks for your help in advance. I am relatively new to developing web api applications. I am faced with developing an application that requires the return of approximately 80 columns from a SQL table. The examples shown in the Microsoft
documentation typically show some sort of database call with a Using loop that in turn requires a separate class with get-set properties. Given the number of columns I am dealing with, this presents a lot of overhead to create and maintain. Is there a simpler
way to do this? Any help would be appreciated.
Aug 04, 2015 04:50 PM|mostafasydney|LINK
You can create Database-First EDMX for the existing database which will migrate all your database tables into your project. You will be able to access the database for the data operations such as read, write, delete, update etc.
For the table having large number of columns, based on your need you can create ViewModel consisting of necessary columns and use the ViewModel in your controllers and views for working with the data. When you need to save or update database values, then
assign the data from the ViewModel to the generated entity for the table and perform the database operations.
If you have the columns in the table which are NOT NULLABLE, make sure that you need to provide values for them otherwise you will not be able to save the record.
Hope this will help.
Aug 05, 2015 03:59 PM|kmcnet|LINK
Thanks for the response. What if the project is already created?
Aug 05, 2015 05:15 PM|mostafasydney|LINK
If you have to use existing database, you need to stick with Database-First, where you create the EDMX and use the generated classes (Model) for saving and accessing data from the database.
It would be possible for Code-First for new tables that you need to add - then use code-first for those models only.
Aug 08, 2015 11:31 AM|kmcnet|LINK
Thanks for the response. Looks like this is way easier.