Entity Framework working with SQL Server views for ASP. NET web api

a 夏天 提交于 2019-12-11 08:48:14

问题


I am researching my first RESTful API project to interact with the automation side of our ERP system.

I am planning a SPA like here

The simple web page is to provide users with a list of purchase requisitions they must approve or decline.

The app will retrieve the data from a SQL Server view into a collection. As the user approves or declines the requisition this is recorded in the object and when the User presses 'Update ERP' the app will build a XML list of the collection and using a SQL Server stored procedure insert it into the SQL database of the ERP for the automation process to pick up and process

I have three questions

  1. The examples uses SQL Server tables in EF should I build the view in the "model" (some how!) or can I use my SQL Server view?

  2. If I use my SQL Server view, does it need an ID / unique key column (for example row number) to make EF work better?

  3. Would be better using a C# class to do the data retrieval and sending the xml data into the database with SQL Server stored procedure than EF?


回答1:


The exampe uses SQL tables in EF should I build the view in the "model" (some how!) or can I use my SQL view?

Use the "Code First to an Existing Database" workflow, and you can select the views from the database, and EF will generate the classes.

If I use my SQL view does it need an ID/ unique key column (for example row number) to make EF work better?

EF will try to identify the key columns, but it's not very smart about it. You can change the model after the initial generation. The key doesn't matter very much if you don't update the entities, but every Entity still needs a key.

Would be better using a C# class to do the data retrieval and sending the xml data into the database with SQL stored procedure than EF?

No I would use EF for the retrieval, but probably straight ADO.NET to call the stored procedure.



来源:https://stackoverflow.com/questions/51468998/entity-framework-working-with-sql-server-views-for-asp-net-web-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!