List<tblX> messages = (from x in db.tblX where x.msg_id == id_id
|| x.name == firstName select x).ToList();
I get the error:
The property ‘x’ on ‘tblX’ could not be set to a ‘null’ value. You must set this property to a non-null value of type ‘Int16’.
I have a property msg_blocked in db, which is nullable and integer. I know that I need to make a conversion, but I don’t use it or need it anywhere in my linq.
Seems like your class definition for tblX doesn’t match the database representation, so either modify your class to accept a nullable value, or just project out the required fields:
Addendum: The reason you run into this problem is behind the scenes when you
select xthis is translated into a
select new tblXwhich projects into all its available fields. The code provided is more explicit and specifies which fields to query for and then project into.