Я использую ASP.net Identity и у меня есть модель, которая включает в себя идентификатор пользователя:
public class Response
{
public int Id { get; set; }
public virtual Survey Survey { get; set; }
public string Userid { get; set; }
public int Ftes { get; set; }
public int Members { get; set; }
public decimal Assets { get; set; }
public decimal Budget { get; set; }
public string Govbody { get; set; }
}
, а также таблицу, в которой есть ответчик:
public class Basiclife
{
[Key]
public int Id { get; set; }
public int ResponseId { get; set; }
public string Plantype { get; set; }
public int Enrolledftes { get; set; }
public decimal Pctemployer { get; set; }
public decimal Fixedbenamt { get; set; }
public decimal Salarymult { get; set; }
public decimal Bencap { get; set; }
}
Я пытаюсь добавить запись Basiclife и установить Id равным идентификатору responseId пользователя, вошедшего в систему (у каждого пользователя будет только один Response):
[HttpPost]
public ActionResult CreateBasicLifeResponse(IEnumerable<BasicLifeResponseViewModel> response)
{
string currentUserId = User.Identity.GetUserId();
Response response = db.response.FirstOrDefault(x => x.Userid = currentUserId);
int responseid = response.Id;
foreach(var y in response)
{
Basiclife blr = new Basiclife();
blr.ResponseId = responseid;
/*
* the rest of the required BasicLife fields
* */
}
return View();
}
Я получаю сообщение об ошибке "Cannotнеявное преобразование строки типа в bool в строке Response response = db.response.FirstOrDefault(x => x.Userid = currentUserId);
Учитывая, что все идентификаторы являются строками, я не уверен, почему он пытается преобразовать в bool.