简体   繁体   English

如何将参数从LINQ查询传递到SQL视图?

[英]How do I pass a parameter from a LINQ query into a SQL View?

I have a view on SQL that I am using to pull data. 我对要用来提取数据的SQL有一个看法。 However, I keep getting a timeout error the last few days. 但是,最近几天我一直收到超时错误。 The view is pulling data for all the ID's instead of one by one. 该视图正在提取所有ID的数据,而不是一一提取。 So my idea is to pull the data per ID. 所以我的想法是提取每个ID的数据。 How do I pass the ID into the View using a parameter / declaring a variable? 如何使用参数/声明变量将ID传递到视图中?

I just need a simple example. 我只需要一个简单的例子。

We don't want to change the timeout limit as it's not a permanent solution. 我们不想更改超时限制,因为它不是永久解决方案。 The data is growing every day, so it's not a reasonable change. 数据每天都在增长,所以这不是一个合理的变化。

You can't pass parameters to a view. 您不能将参数传递给视图。 For this purpose, you can use a stored procedure instead. 为此,您可以改用存储过程。

Use the link below to create your stored procedure: 使用下面的链接创建您的存储过程:

https://www.mssqltips.com/sqlservertutorial/162/how-to-create-a-sql-server-stored-procedure-with-parameters/ https://www.mssqltips.com/sqlservertutorial/162/how-to-create-a-sql-server-stored-procedure-with-parameters/

And if you want to use your stored procedure in linq, please read this link: 如果要在linq中使用存储过程,请阅读以下链接:

https://www.c-sharpcorner.com/UploadFile/dhananjaycoder/using-stored-procedure-in-linq/ https://www.c-sharpcorner.com/UploadFile/dhananjaycoder/using-stored-procedure-in-linq/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM