asp.net - Entity Framework working with SQL Server views for ASP. NET web api
问题描述
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?
解决方案
该示例在 EF 中使用 SQL 表,我应该在“模型”中构建视图(某种方式!)还是可以使用我的 SQL 视图?
使用“ Code First to an Existing Database ”工作流程,您可以从数据库中选择视图,EF 将生成类。
如果我使用我的 SQL 视图,它是否需要一个 ID/唯一键列(例如行号)才能使 EF 更好地工作?
EF 将尝试识别关键列,但它不是很聪明。您可以在初始生成后更改模型。如果您不更新实体,密钥并不重要,但每个实体仍然需要一个密钥。
使用 C# 类进行数据检索并使用 SQL 存储过程将 xml 数据发送到数据库中会比 EF 更好吗?
不,我会使用 EF 进行检索,但可能直接使用 ADO.NET 来调用存储过程。
推荐阅读
- python - 如何按关键字将列表拆分为嵌套列表?
- flutter - Dart / Flutter:在没有上下文的页面之间导航(使用 Navigator)(所以没有 Navigator.push?)
- python - 组的Python正则表达式以匹配金额之前的文本
- python - MySql:将python列表插入表中
- python - 如何在函数内部在 pyqt5 中“打印”?
- python - 了解 BST 遍历的打印输出
- sql - Sqlite for 循环删除非常慢
- python - 在 python 上的startswith 操作在 . URL中的字符
- python - 如何将第二个轴添加到 matplotlib/seaborn 条形图并使次要点与正确的条形对齐?
- flutter - 在 Flutter App 中调用平板纸扫描仪