我正在使用Entity Framework数据库的第一种方法。我正在为我的存储过程创建复杂的类型,以便我可以在我的ASP.NET MVC应用程序中使用它。我需要创建复杂类型,因为Entity Framework不会为我创建它。我无法使用创建的实体类映射复杂类型。我收到了错误
无法将类型'System.Collections.Generic.List'隐式转换为'int'
有人可以告诉我这是什么问题吗?
存储过程:
CREATE PROCEDURE [dbo].[spUserExists]
(@NetworkID varchar(20),
@Domain varchar(50),
@RoleID int)
AS
BEGIN
set nocount on
----------------------------------------
-- variables
----------------------------------------
-- error
declare @ErrorMessage nvarchar(2048), @ErrorSeverity int, @ErrorState int
----------------------------------------
-- exists
----------------------------------------
declare @UserExists int; set @UserExists = 0
begin try
select @UserExists = 1
where exists (Select up.NetworkID, up.Domain, ur.RoleId
from dbo.UserProfile up
inner join UserProfileRoleLink ur on up.UserProfileId = ur.UserProfileId
where up.NetworkID = @NetworkID
and up.Domain = @Domain
and ur.RoleId = @RoleID)
end try
begin catch
select
@ErrorMessage = dbo.GetErrorMessage('Exists', error_message(), object_schema_name(@@procid), object_name(@@procid), error_line()),
@ErrorSeverity = error_severity(),
@ErrorState = error_state();
raiserror(@ErrorMessage, @ErrorSeverity, @ErrorState);
return
end catch
select @UserExists as UserExists
END
实体类:
public class ValidUser
{
public Int32 UserExists { get; set; }
}
功能导入:
复杂类型:
映射并返回值:
public static System.Int32 UserValidate()
{
using (var db = new MCREntities())
{
var isValid = db.spUserExists(GetShortname(), GetDomain(), 1);
return Mapper.Map<List<ValidUser>>(isValid);
}
}
答案 0 :(得分:0)
我认为你需要UserValidate返回类型的方法是List而不是Int32。