linq to sql - 存储过程 - webservice [英] linq to sql - stored procedure - webservice

查看:117
本文介绍了linq to sql - 存储过程 - webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个包含3个项目的c#解决方案:

1. linq-to-sql业务层。

2. Web服务层。

3.普通代理,网络消费者来自我的所有用户界面。



问题:

我无法从代码中使用的存储过程中获取nvarchar值。



程序:

  ALTER   PROCEDURE  [dbo]。[spGetLocked ] 
- 在此处添加存储过程的参数
@ appid varchar 10 ),
@ examcode varchar 10
AS

BEGIN
- 添加SET NOCOUNT ON以防止额外的结果集
- 干扰SELECT语句。
SET NOCOUNT ON ;

- 在此处插入程序语句
SELECT record_lock
FROM user_result
WHERE appid = @ appid exam_id = @ examcode

RETURN

END



设计师内置的代码:

 [ global  :: System.Data.Linq.Mapping.FunctionAttribute(Name =   dbo .spGetLocked)] 
public ISingleResult< spgetlockedresult> spGetLocked([ global :: System.Data.Linq.Mapping.ParameterAttribute(DbType = VarChar(10))] string appid,[ global :: System.Data.Linq.Mapping.ParameterAttribute(DbType = VarChar(10)) ] string examcode)
{
IExecuteResult result = this .ExecuteMethodCall( this ,((MethodInfo)(MethodInfo.GetCurrentMethod())),appid,examcode);
return ((ISingleResult< spgetlockedresult>)(result.ReturnValue));
}



我尝试调用程序:



 ExamBusiness.ExamsDataContext db =  new  ExamBusiness.ExamsDataContext(); 

string recLock = db.spGetLocked(appid,examid)。

return recLock;





我是试图获取字段的值 record_lock (T或F) nvarchar(1)我的 check_login 代码。



请帮忙,我已经连续10个小时被困了。



谢谢你,
Suzanne

解决方案

我假设以下代码需要更换:



 ExamBusiness.ExamsDataContext db =  new  ExamBusiness.ExamsDataContext(); 

string recLock = db.spGetLocked(appid,examid)。

return recLock;





To



 ExamBusiness.ExamsDataContext db =  new  ExamBusiness.ExamsDataContext(); 

ISingleResult< spgetlockedresult> result = db.spGetLocked(appid,examid);

//检查result.FirstOrDefault null
< span class =code-keyword> string recLock = result.FirstOrDefault()。record_lock;

return recLock; < / spgetlockedresult >







请参阅 http://msdn.microsoft.com/en-us/library/bb534556。 aspx [ ^ ]


A c# solution with 3 projects:
1. linq-to-sql Business Layer.
2. Web Service layer.
3. Normal proxy, web consumer fromnt end with all my UI.

Problem:
I cannot get an nvarchar value from my stored procedure that I can use in the code.

The Procedure:

ALTER PROCEDURE [dbo].[spGetLocked]
	-- Add the parameters for the stored procedure here
	@appid varchar(10),
	@examcode varchar(10)
AS

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT record_lock 
	FROM user_result
	WHERE appid = @appid and exam_id = @examcode
	
	RETURN
	
END


The code built in the designer:

[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.spGetLocked")]
		public ISingleResult<spgetlockedresult> spGetLocked([global::System.Data.Linq.Mapping.ParameterAttribute(DbType="VarChar(10)")] string appid, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="VarChar(10)")] string examcode)
		{
			IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), appid, examcode);
			return ((ISingleResult<spgetlockedresult>)(result.ReturnValue));
		}


My attempt at calling the procedure:

ExamBusiness.ExamsDataContext db = new ExamBusiness.ExamsDataContext();

string recLock = db.spGetLocked(appid, examid).

return recLock;



I am trying to get the value of field record_lock (T or F) nvarchar(1) for a business decision in my check_login code.

Please help, I have been stuck for 10 straight hours.

Thank you,
Suzanne

解决方案

I assume following code need to be replaced:

ExamBusiness.ExamsDataContext db = new ExamBusiness.ExamsDataContext();

string recLock = db.spGetLocked(appid, examid).

return recLock;



To

ExamBusiness.ExamsDataContext db = new ExamBusiness.ExamsDataContext();

ISingleResult<spgetlockedresult> result = db.spGetLocked(appid, examid);

//Check result.FirstOrDefault for not null 
string recLock = result.FirstOrDefault().record_lock; 

return recLock;</spgetlockedresult>




Please refer http://msdn.microsoft.com/en-us/library/bb534556.aspx[^]


这篇关于linq to sql - 存储过程 - webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆