这是我的存储过程实现:
ALTER procedure [dbo].[ShowProjectByNameOfPerson]
(@name as nvarchar)
as begin
select Personality.id,COUNT(*) as cnt into #test
from Personality,Project,Personal_project
where Personality.Id = Personal_project.PersonalityId_FK
and Project.Id = Personal_project.ProjectId_FK
and Personality.FullName like N'%'+@name+'%'
group by Personality.Id
order by cnt desc
select * from #test,Personality
where #test.id = Personality.id
end
我在ASP.Net项目中创建了Linq ToSQL类项。我将过程分配给DBML文件。 但是当我想在制作上下文的实例后使用该过程时,我得到了这个错误:
Cannot assign void to an implicitly-typed local variable
No overload for method 'ShowProjectByNameOfPerson'
这是.cs文件中存储过程的调用代码:
DataClassesDataContext db = new DataClassesDataContext();
var lst = db.ShowProjectByNameOfPerson(txt);
我该如何解决这个问题?
感谢高级。
答案 0 :(得分:3)
您对各种t-sql函数类型感到困惑。
你想要的是:
create function [dbo].[ShowProjectByNameOfPerson] (@name as nvarchar)
returns table
as return (
select
Personality.Id, Personality.FullName,
COUNT(*) as cnt
from Personality
inner join Personal_project
on Personality.Id = Personal_project.PersonalityId_FK
where Personality.FullName like N'%' + @name + N'%'
group by Personality.Id, Personality.FullName
order by cnt desc
);
请参阅MSDN参考以了解语法变体及其含义: http://msdn.microsoft.com/en-us/library/ms186755.aspx
此外,您应该尽量避免不必要地使用临时表(请参阅我如何更改您的代码)。