简体   繁体   English

错误无法将void分配给隐式类型的局部变量

[英]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.

相关问题 无法使用var和foreach将void分配给隐式类型的局部变量 - Cannot assign void to an implicitly-typed local variable with var and foreach 无法为WP 8.1中的隐式类型的局部变量分配void - Cannot assign void to an implicitly-typed local variable in WP 8.1 无法为隐式类型的局部变量分配void - cannot assign void to implicitly-typed local variable 无法将void分配给隐式类型的局部变量 - Cannot assign void to an implicitly-typed local variable 无法在单元测试中将 void 分配给隐式类型的变量 - Cannot assign void to an implicitly-typed variable in unit test Linq ForEach - 返回不能将&#39;void&#39;分配给隐式类型的局部变量 - Linq ForEach - Returning cannot assign 'void' to an implicitly-typed local variable 无法使用Entity Framework 6将空值分配给隐式类型的局部变量 - Cannot assign a void to an implicitly-typed local variable using Entity Framework 6 .Insert问题和错误提示无法将void分配给隐式类型的变量 - Problems with .Insert and error saying Cannot assign void to an implicitly-typed variable 无法将方法组分配给隐式类型的局部变量 - Cannot assign method group to an implicitly-typed local variable 无法分配 <null> 到隐式类型的局部变量 - Cannot assign <null> to an implicitly-typed local variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM