无法隐式转换类型'int?' 'int' [英] Cannot implicitly convert type 'int?' to 'int'
问题描述
在此查询中,我有3条记录(int-(telefon = d.telefon),decimal-(pesel = d.pesel),decimal-(nip = d.nip))是字符串.
In this query I have 3 records (int-(telefon = d.telefon), decimal-(pesel = d.pesel), decimal-(nip = d.nip)) another records are strings.
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();
}
我有错误:
无法隐式转换类型'int?'到"int".显式转换 存在(您是否缺少演员表?)
Cannot implicitly convert type 'int?' to 'int'. An explicit conversion exists (are you missing a cast?)
和另外两个带有十进制?"的错误而不是'int?'.
and two another errors with 'decimal?' instead '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不可为空,其余的则允许为空
Only imie and nazwisko are nonnullable, rest have allow null
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
现在工作.我更改了型号:
decimal to decimal?
和
int to int?
谢谢大家的帮助
推荐答案
在您的uzytkownikModel类中,可为空的属性应声明为"int?".或十进制?"而不是"int"和"decimal".
In your uzytkownikModel class, the properties that are nullable should be declared as "int?" or "decimal?" instead of "int" and "decimal".
这篇关于无法隐式转换类型'int?' 'int'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!