gpt4 book ai didi

linq - 无法将类型 'int?'隐式转换为 'int'

转载 作者:行者123 更新时间:2023-12-03 13:40:02 25 4
gpt4 key购买 nike

在此查询中,我有3条记录(int-(telefon = d.telefon),decimal-(pesel = d.pesel),decimal-(nip = d.nip))另一个记录是字符串。

public ActionResult detail(int LoginID)
{
var user = (from d in baza.uzytkowniks
where LoginID == d.LoginID
select new uzytkownikModel {
imie = d.imie,
nazwisko = d.nazwisko,
telefon = d.telefon,
pesel = d.pesel,
nip = d.nip,
email = d.email,
adres_zamieszkania = d.adres_zamieszkania}).ToList();

ViewBag.daneuser = user;
return View();
}

我有错误:

Cannot implicitly convert type 'int?' to 'int'. An explicit conversion exists (are you missing a cast?)



还有另外两个“小数?”错误而是“int?”。

模型:
 public class uzytkownikModel
{
[Required]
public string imie { get; set; }

[Required]
public string nazwisko { get; set; }


public decimal pesel { get; set; }
public decimal nip { get; set; }

public string adres_zamieszkania { get; set; }
public int telefon { get; set; }
public string email { get; set; }

}

只有imie和nazwisko不可为空,其余的则允许为null

////////////////////////////////////////////////// //////////////////////////////////////////////////// //////////////////////////////

现在工作。我更改了型号:
   decimal to decimal?


int to int?

谢谢大家的帮助

最佳答案

在您的uzytkownikModel类中,可为空的属性应声明为“int?”。或“十进制?”而不是“int”和“decimal”。

关于linq - 无法将类型 'int?'隐式转换为 'int',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8053698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com