我从LINQ
调用了以下Web API
查询。当我打破查询并检查值时,AlertType显示Enum
的字符串值。当我在浏览器中检查响应时,alertType显示枚举的int值。谁能告诉我这里发生了什么?
[Route("api/Alert/GetAlertsByUser")]
public async Task<List<AlertConfigVM>> GetAlertsByUser()
{
try
{
var user = await securityService.GetUser(User.Identity.Name);
return await service.GetAlertsByUser(user.Id);
}
catch (Exception ex)
{
ErrorHandler.ProcessApiError(ex);
return null;
}
}
这是linq查询
async public Task<List<AlertConfigVM>> GetAlertsByUser(string userId)
{
using (var ctx = new JudgePortalContext())
{
var query = ctx.UserAlerts.Include(x=>x.DocumentType).Where(x => x.UserId == userId).ToList();
var alerts = query.Select(u => new AlertConfigVM
{
UserId = u.UserId,
Destination = u.AlertDestination,
AlertType = (AlertTypes)u.TypeofAlert,
HourInterval = u.IntervalAsHours,
DocumentTypeName= u.DocumentType?.Name??string.Empty
}).ToList();
return alerts;
}
}
这是返回类型和枚举
public enum AlertTypes
{
Email=0,
Text =1
}
public class AlertConfigVM
{
public int Id { get; set; }
public string UserId { get; set; }
public User User { get; set; }
public AlertTypes AlertType { get; set; }
public string Destination { get; set; }
public int? DocumentTypeId { get; set; }
public string DocumentTypeName { get; set; }
public int? HourInterval { get; set; }
}