How LINQ to SQL executes a stored procedure and returns a temporary table of stored procedures

Source: Internet
Author: User

Check Google, this approach can solve

My stored procedure is this:

CREATE procedure Cal_month_dep_fast @begdt datetime, @endt datetime
As
。。。。。。。。。

Select Dep_no, Prod_no, Batch_no, Prod_add, Dep_date, Dep_num, Inv_num,lest_num, Buy_price from #tempresult

The LINQ to SQL can be resolved by the following methods

1 Build a Class (remember to be public, otherwise error)

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Data.Linq.Mapping;
Using System.Linq.Expressions;

Namespace SBSC
{
[Table]
public partial class Myproc_result
{
Public Myproc_result () {}

[Column]
public string dep_no;
[Column]
public string prod_no;
[Column]
public string batch_no;
[Column]
public string Prod_add;
[Column]
Public DateTime dep_date;
[Column]
public decimal dep_num;
[Column]
public decimal inv_num;
[Column]
public decimal lest_num;
[Column]
public decimal buy_price;
}

}

2 then add the following in the Designer.cs file for DBML in LINQ: Remember that the name may be slightly changed from the previous stored procedure name

[Function (Name = "Dbo.cal_month_dep_fast")]
Public ienumerable<myproc_result> cal_month_dep_fast2 (datetime BEGDT, datetime endt)
{
Iexecuteresult result = this. Executemethodcall (This, ((MethodInfo) (Methodinfo.getcurrentmethod ())), BEGDT, Endt);
return result. ReturnValue as ienumerable<myproc_result>;
}

That's it.

How LINQ to SQL executes a stored procedure and returns a temporary table of stored procedures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.