create proc sp_singleresultset
as
set nocount on
select * from customers
|
[Function(Name="dbo.sp_singleresultset")]
public ISingleResult<sp_singleresultsetResult> sp_singleresultset()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((ISingleResult<sp_singleresultsetResult>)(result.ReturnValue));
}
|
SET FMTONLY ON;
exec Northwind.dbo.sp_singleresultset
SET FMTONLY OFF;
|
var 单结果集存储过程 =
from c in ctx.sp_singleresultset()
where c.CustomerID.StartsWith("A")
select c;
|
EXEC @RETURN_VALUE = [dbo].[sp_singleresultset]
-- @RETURN_VALUE: Output Int32 (Size = 0; Prec = 0; Scale = 0) []
|
create proc [dbo].[sp_withparameter]
@customerid nchar(5),
@rowcount int output
as
set nocount on
set @rowcount = (select count(*) from customers where customerid = @customerid)
|
int? rowcount = -1;
ctx.sp_withparameter("", ref rowcount);
Response.Write(rowcount);
ctx.sp_withparameter("ALFKI", ref rowcount);
Response.Write(rowcount);
|
EXEC @RETURN_VALUE = [dbo].[sp_withparameter] @customerid = @p0, @rowcount = @p1 OUTPUT
-- @p0: Input StringFixedLength (Size = 5; Prec = 0; Scale = 0) []
-- @p1: InputOutput Int32 (Size = 0; Prec = 0; Scale = 0) [-1]
-- @RETURN_VALUE: Output Int32 (Size = 0; Prec = 0; Scale = 0) []
|
create proc [dbo].[sp_withreturnvalue]
@customerid nchar(5)
as
set nocount on
if exists (select 1 from customers where customerid = @customerid)
return 101
else
return 100
|
Response.Write(ctx.sp_withreturnvalue(""));
Response.Write(ctx.sp_withreturnvalue("ALFKI"));
|
create proc [dbo].[sp_multiresultset]
as
set nocount on
select * from customers
select * from employees
|
[Function(Name="dbo.sp_multiresultset")]
public ISingleResult<sp_multiresultsetResult> sp_multiresultset()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((ISingleResult<sp_multiresultsetResult>)(result.ReturnValue));
}
|
[Function(Name="dbo.sp_multiresultset")]
[ResultType(typeof(Customer))]
[ResultType(typeof(Employee))]
public IMultipleResults sp_multiresultset()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return (IMultipleResults)(result.ReturnValue);
}
|
var 多结果集存储过程 = ctx.sp_multiresultset();
var Customers = 多结果集存储过程.GetResult<Customer>();
var Employees = 多结果集存储过程.GetResult<Employee>();
GridView1.DataSource = from emp in Employees where emp.FirstName.Contains("A") select emp;
GridView1.DataBind();
GridView2.DataSource = from c in Customers where c.CustomerID.StartsWith("A") select c;
GridView2.DataBind();
|
create proc sendmessage
@username varchar(50),
@message varchar(500)
as
insert into tbguestbook
(id,username,posttime,[message],isreplied,reply)
values
(newid(),@username,getdate(),@message,0,'')
|
protected void btn_SendMessage_Click(object sender, EventArgs e)
{
tbGuestBook gb = new tbGuestBook();
gb.UserName = tb_UserName.Text;
gb.Message = tb_Message.Text;
ctx.tbGuestBooks.Add(gb);
ctx.SubmitChanges();
SetBind();
}
|
EXEC @RETURN_VALUE = [dbo].[sendmessage] @username = @p0, @message = @p1
-- @p0: Input AnsiString (Size = 5; Prec = 0; Scale = 0) [zhuye]
-- @p1: Input AnsiString (Size = 11; Prec = 0; Scale = 0) [new message]
-- @RETURN_VALUE: Output Int32 (Size = 0; Prec = 0; Scale = 0) []
|
create proc delmessage
@id uniqueidentifier
as
delete tbguestbook where id=@id
|
EXEC @RETURN_VALUE = [dbo].[delmessage] @id = @p0
-- @p0: Input Guid (Size = 0; Prec = 0; Scale = 0) [9e3c5ee3-2575-458e-899d-4b0bf73e0849]
-- @RETURN_VALUE: Output Int32 (Size = 0; Prec = 0; Scale = 0) []
|
create proc replymessage
@id uniqueidentifier,
@reply varchar(500)
as
update tbguestbook set reply=@reply,isreplied=1 where id=@id
|
EXEC @RETURN_VALUE = [dbo].[replymessage] @id = @p0, @reply = @p1
-- @p0: Input Guid (Size = 0; Prec = 0; Scale = 0) [67a69d0f-a88b-4b22-8939-fed021eb1cb5]
-- @p1: Input AnsiString (Size = 6; Prec = 0; Scale = 0) [464456]
-- @RETURN_VALUE: Output Int32 (Size = 0; Prec = 0; Scale = 0) []
|
create proc modiusername
@oldusername varchar(50),
@newusername varchar(50)
as
update tbguestbook set username=@newusername where username = @oldusername
|
var messages = from gb in ctx.tbGuestBooks
select gb;
foreach (var gb in messages)
{
if(gb.UserName == "admin")
gb.UserName = "notadmin";
}
|
SELECT [t0].[ID], [t0].[UserName], [t0].[PostTime], [t0].[Message], [t0].[IsReplied], [t0].[Reply]
FROM [dbo].[tbGuestBook] AS [t0]
EXEC @RETURN_VALUE = [dbo].[modiusername] @oldusername = @p0, @newusername = @p1
-- @p0: Input AnsiString (Size = 5; Prec = 0; Scale = 0) [admin]
-- @p1: Input AnsiString (Size = 8; Prec = 0; Scale = 0) [notadmin]
-- @RETURN_VALUE: Output Int32 (Size = 0; Prec = 0; Scale = 0) []
|