LINQ 学习笔记之存储过程!

首先在数据库中随便创建两个存储过程,一个待参数,一个不待参数,

create  proc sp_SelectStudent
as
begin
select * from Student
end

 

第二个:


create proc [dbo].[sp_AddClasses](@ClasseName nvarchar(20))
as
begin
insert into Classes values(@ClasseName)

end

然后在服务器资源管理器里面你可以看到如下图的两个存储过程:

 

 

我们把存储过程拖放到.DBML里,如下图:

我们在看看IDE为我们自动生成的代码,打开Demo.designer.cs

 

 [Function(Name="dbo.sp_AddClasses")]
  public int sp_AddClasses([Parameter(Name="ClasseName", DbType="NVarChar(20)")] string classeName)
  {
   IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), classeName);
   return ((int)(result.ReturnValue));
  }

这是Function函数IDE自动生成的,也许你在奇怪,IDE怎么知道我们的存储过程会返回什么类型的数据呢,其实在我们把存储过程拖入.DBML里的时候,IDE就执行了,EXEC sp_Addclasses 。

 

那么我们怎么试用存储过程呢,其他和调用函数一样:

DemoDataContext db = new DemoDataContext();
                var result = from p in db.sp_SelectStudent() select p;
                this.GridView1.DataSource = result;
                this.GridView1.DataBind();

 

OK ,先写到这里,感觉充实多了!

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值