[英]ERROR Cannot assign void to an implicitly-typed local variable
I have the stored procedures in sql server to insert a user but i'm getting this error when trying to map the sp with a DTO class I have. 我在sql server中具有存储过程以插入用户,但是在尝试使用我拥有的DTO类映射sp时遇到此错误。
DataClasses1DataContext _dataContext = new DataClasses1DataContext();
public List<WebUserDTO> InsertUser (string Username, string UserPassword, string FullName, string Email)
{
var user = _dataContext.WebUser_InsertUser(Username, UserPassword, FullName, Email);
return user.Select(aux => new WebUserDTO()
{
UserName = aux.Username,
UserPassword = aux.UserPassword,
FullName = aux.FullName,
Email = aux.Email
}).ToList();
}
Error shows here: var user = _dataContext.WebUser_InsertUser(Username, UserPassword, FullName, Email);
错误显示在这里:
var user = _dataContext.WebUser_InsertUser(Username, UserPassword, FullName, Email);
My Insert sps are the following and I have correct results when executing dbo.WebUser_InsertUser
in sql server 我的插入sps是以下内容,并且在sql server中执行
dbo.WebUser_InsertUser
时我得到正确的结果
CREATE PROC dbo.WebUser_InsertUser0
@Username AS NVARCHAR (20),
@UserPassword AS NVARCHAR (20),
@FullName AS NVARCHAR (50),
@Email AS NVARCHAR (50),
@IdUser AS INT OUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO dbo.WebUser (UserName, UserPassword, FullName, Email)
VALUES (@UserName, @UserPassword, @FullName, @Email)
SET @IdUser = SCOPE_IDENTITY()
RETURN @IdUser;
END
GO
CREATE PROC dbo.WebUser_InsertUser
@Username1 AS NVARCHAR (20),
@UserPassword1 AS NVARCHAR (20),
@FullName1 AS NVARCHAR (50),
@Email1 AS NVARCHAR (50)
AS
BEGIN
SET NOCOUNT ON;
DECLARE
@UserId1 AS INT
EXEC dbo.WebUser_InsertUser @UserName1, @UserPassword1, @FullName1, @Email1, @UserId1 OUT
SELECT W.IdUser, W.UserTypeId, W.Username, W.UserPassword, W.FullName, W.Email
FROM dbo.WebUser AS W
WHERE W.IdUser = @UserId1
RETURN;
END
Most probably you need something like that: 很可能您需要这样的东西:
public List<WebUserDTO> InsertUser (string Username, string UserPassword, string FullName, string Email)
{
_dataContext.WebUser_InsertUser(Username, UserPassword, FullName, Email);
// since you did not provide _dataContext type definition
// I can only guess how your user collection is called in your DbContext.
return _dataContext.users.Select(aux => new WebUserDTO()
{
UserName = aux.Username,
UserPassword = aux.UserPassword,
FullName = aux.FullName,
Email = aux.Email
}).ToList();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.