Matthis Kohli Matthis Kohli - 6 months ago 11
Vb.net Question

VB.NET LINQ Method Syntax disallows implicit conversions from 'Integer?' to 'Integer'

Compare weirdness when working with LINQ and Entity Framework.
I want to retrieve an ID from my DB and I get this weird message.

I could simply fix it as you can see but I want to understand why this happens.

Question:

Why do I get this error message even if I check with "HasValue" or I use "FirstOrDefault"? It can't be null in my opinion but I obviously miss something.

Code and Error

Answer

Add .Value is you are 100% sure the Integer? has a value.

Why do I get this error message even if I check with "HasValue"

Entity Framework just uses the objects you give it. It can't create a new object where OPX_ isn't nullable.