我试过谷歌搜索但没有成功,唯一的问题是没有找到解决方案:http ://social.msdn.microsoft.com/Forums/pl-PL/linqtosql/thread/cee9df70-f38d-40be -ab1a-6697fac461d8
SP
@CustomerName varchar(150) = NULL
DECLARE @SQL nvarchar(2000)
SET @SQL = 'SELECT A.[id], A.[startTime], N.firstName AS CustomerForename, N.surname AS CustomerSurname, O.Email AS OfficerEmail, L.Description AS Location, AT.description AS Type, ATC.description AS Category,AD.cancelledById, A.Deleted
FROM [Calendar].[dbo].[Appointments] AS A
INNER JOIN [Calendar].[dbo].[Name] AS N ON A.Id = N.appointmentId
INNER JOIN [Calendar].[dbo].[Officers] AS O ON A.Officer = O.Id
INNER JOIN [Calendar].[dbo].[Locations] AS L ON A.Location = L.Id
INNER JOIN [Calendar].[dbo].[AppointmentTypes] AS AT ON A.Type = AT.Id
INNER JOIN [Calendar].[dbo].[AppointmentTypeCategories] AS ATC ON AT.category = ATC.Id
INNER JOIN [Calendar].[dbo].[AppointmentDetails] AS AD ON A.Id = AD.appointmentId
WHERE A.[id] > 1'
IF @CustomerName IS NOT NULL
SET @SQL = @SQL + ' AND (CustomerForename LIKE % + @CustomerName + % OR CustomerSurname LIKE % + @CustomerName + %)'
EXECUTE sp_executesql @SQL
LINQ
public IQueryable<Appointment> GetAppointmentsBySearchCriteria(int appointmentId, string customerName, int officer, int location, int type, DateTime to, DateTime from)
{
var data = _db.GetAppointmentsBySearchCriteria(appointmentId,customerName,officer,location,type,to,from);
foreach (var appointment in data)
{
}
}
这是我收到的错误:无法将 void 分配给隐式类型的局部变量
我尝试添加以下内容:
RETURN EXECUTE sp_executesql @SQL
EXECUTE sp_executesql @SQL
RETURN
当 SP 被拖入 DBML 时,我收到以下消息:无法检测到以下存储过程的返回类型。为每个存储过程设置返回类型
提前感谢您的帮助。
克莱尔:-)