In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the example analysis of Linq to object, which is very detailed and has certain reference value. Friends who are interested must finish it!
When learning Linq to object, we often encounter Linq to object problems. Here we will introduce the solutions to XX problems.
For a normal stored procedure, first run the following code in the query analyzer to create a stored procedure:
Create proc sp_singleresultset as set nocount on select * from customers
Then open IDE's server explorer. Earlier, we dragged the table from the table to the dbml design view. This time we found the stored procedure we just created from the stored procedure, and then dragged it to design view. You can see that a sp_singleresultset method has been created in the methods panel
Then open Northwind.designer.cs and find the following code:
[Function (Name= "dbo.sp_singleresultset")]
Public ISingleResult sp_singleresultset ()
{
IExecuteResult result = this.ExecuteMethodCall (this
((MethodInfo) (MethodInfo.GetCurrentMethod ()
Return ((ISingleResult) (result.ReturnValue))
}
We can find that IDE separately generated an entity definition that returns the result set for this stored procedure, and you may wonder, how does IDE know what data the stored procedure will return? In fact, when you drag a stored procedure into the dbml design view, IDE executes a command similar to the following:
SET FMTONLY ON; exec Northwind.dbo.sp_singleresultset SET FMTONLY OFF
This allows you to directly get the metadata returned by the stored procedure without having to execute the stored procedure.
In fact, what we stored procedure returns is the customer table data, if you think it is wasteful to set the result set entity separately for the stored procedure, you can adjust the return type from "automatically generated type" to Customer in the properties window of the stored procedure, but later you can only delete the stored procedure in the method panel and add it again to restore to "automatically generated type". Below, we can write the following Linq to object code to query:
Var single result set stored procedure = from c in ctx.sp_singleresultset () where c.CustomerID.StartsWith ("A") select c
It is Linq to object here, because the query syntax is not translated into SQL, but is queried from the returned object of the stored procedure. The SQL code is as follows:
EXEC @ RETURN_VALUE = [dbo]. [sp_singleresultset]-- @ RETURN_VALUE: Output Int32 (Size = 0; Prec = 0; Scale = 0) these are all the contents of this article "sample Analysis of Linq to object". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.