实体框架与用于ASP的SQL Server视图一起使用. NET Web API [英] Entity Framework working with SQL Server views for ASP. NET web api

查看:100
本文介绍了实体框架与用于ASP的SQL Server视图一起使用. NET Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究我的第一个RESTful API项目,以与我们的ERP系统的自动化方面进行交互.

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

我正在计划一个此处

简单的网页为用户提供了必须批准或拒绝的购买申请清单.

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

该应用将从SQL Server视图中将数据检索到集合中.当用户批准或拒绝申请时,该请求将记录在对象中,并且当用户按下更新ERP"时,该应用将构建该集合的XML列表,并使用SQL Server存储过程将其插入到ERP的SQL数据库中,以用于自动化流程进行处理

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

我有三个问题

  1. 这些示例在EF中使用SQL Server表还是应该在模型"中构建视图(以某种方式!)还是可以使用SQL Server视图?

  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?

如果我使用SQL Server视图,是否需要一个ID/唯一键列(例如行号)以使EF更好地工作?

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

使用C#类进行数据检索并使用SQL Server存储过程将xml数据发送到数据库中比使用EF更好吗?

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中构建视图,则示例在EF中使用SQL表 模型"(某种方式!)还是可以使用我的SQL视图?

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.

如果我使用SQL视图,是否需要一个ID/唯一键列(对于 示例行号)以使EF更好地工作?

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

EF会尝试识别关键列,但是这样做并不明智.您可以在初始生成后更改模型.如果您不更新实体,则密钥并不重要,但是每个实体仍然需要一个密钥.

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.

使用C#类进行数据检索和发送会更好 使用EF的SQL存储过程将xml数据导入数据库?

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?

不,我将使用EF进行检索,但可能直接使用ADO.NET来调用存储过程.

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

这篇关于实体框架与用于ASP的SQL Server视图一起使用. NET Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆