I have a query
var myquery=from nnn in db.Employees where nnn.empNo=EMPLOYEENO select nnn).FirstOrDefault();
EMPLOYEENO is parameter coming frm method, now in my Emplyees table there are few columns having null values so when this query executes it gives exception "SPECIFIC CAST IS NOT VALID"
Mark TaborPosted Jan 18, 2023, 11:30 AM
Dear all thanks for youre response in helping me out I checked that in my oracle database there is one column name as Employee_Points whose data type is NUMBER in ORacle db and in my class property its type is decimal and when I check the table the values aganist that field is stored as 23.7777777777777777777778888999887788787787677767767 which might be creating an issue as i am using simple select statement so I would like to know how to manipulate it like take on four digits after decimal my query is below
var MyQuery=(from vvv in db.Employees where vvv.EmpId==id select vvv).FirstOrDefault();
Jignesh KumarPosted Jan 18, 2023, 7:00 AM
There is no direct way to check it directly. you need to change your select statement by column by column so you will come to know which field is throwing error, so start will 2 or 3 column in select statement,
try this way you will be identyfied
Mark TaborPosted Jan 18, 2023, 6:48 AM
The issue is not getting record the issue is I am unable to find the exception from the query Jignesh Kumar. it gives specific cast is not valid check my above query
Mark TaborPosted Jan 18, 2023, 6:29 AM
I have checked all the properties vs database column name they match the type my query is
var MyQuery=(from vvv in db.Employees where vvv.EmpId==id select vvv).FirstOrDefault();
id is a parameters basically db.Employees is view and it is having 40 columns i am not sure which column create the issue
Jignesh KumarPosted Jan 18, 2023, 6:24 AM
IF you wish to get all those recods then you need to use or || condition in Linq and insted of FirstorDefault() method you need to use .ToList() method to get all matching records.
Naimish MakwanaPosted Jan 17, 2023, 10:26 AM
The columns having null values, For that columns, make the property nullable.
Mark TaborPosted Jan 17, 2023, 9:46 AM
Sachin Singh & Vishal Joshi Thanks for the response as there are 13 columns in that table and the columns having null are options so If I add them in AND CONDITIN WITH Where clause then the query will exclude all those records which is false I want to get these records no matter if the values of these optional columns like gender ,city ,salary are even having null values
Mark TaborPosted Jan 17, 2023, 9:44 AM
The data type is ok the issue is of null values
Vishal JoshiPosted Jan 17, 2023, 9:27 AM
Hello Mark
Please try the below query can help to check null values
Thanks
Aravind GovindarajPosted Jan 17, 2023, 9:23 AM
Can you please validate SQL column type vs Property type? Check if Is property accepts a null value.
Sachin SinghPosted Jan 17, 2023, 9:16 AM
Naimish MakwanaPosted Jan 17, 2023, 9:04 AM
It may be possible that a column in the database is of a different type than a property in the compiled C# code.
So please, check data type of your DB column and C# class.
Thanks