我在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();
}
此处显示错误:var user = _dataContext.WebUser_InsertUser(Username, UserPassword, FullName, Email);
我的插入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
答案 0 :(得分:0)
很可能你需要这样的东西:
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();
}