Cannot implicitly convert type 'int?' to 'int'.
You'll need to post more code to get a definitive answer, but somewhere one of your variables is nullable, and to assign it to a non-nullable type you need to do .Value
.
For example, if your object d's property imie
is Nullable<int>
, and that is what is causing your problem, you could do this:
imie = d.imie.Value
You will also need to watch for cases where d.imie
is null. For example:
imie = d.imie.HasValue ? d.imie.Value : 0
Or, if you like the ?? operator (which evaluates to the first non-null value):
imie = d.imie ?? 0
(I am just using d.imie
as an example -- there is not enough code posted to pintpoint the exact problem.)
int?
is the Nullable<int>
. Since database columns may be null, the mapped properties are Nullable.
Consider this code which assigns int?
values to int
variables.
int? w = 2;
int? x = null;
int y = w ?? 3;
int z = x ?? 4;
In your uzytkownikModel class, the properties that are nullable should be declared as "int?" or "decimal?" instead of "int" and "decimal".