问题
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
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?
If I use my SQL Server view, does it need an ID / unique key column (for example row number) to make EF work better?
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