Thursday, November 6, 2014

The cast to value type 'Double' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type


The cast to value type 'Double' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type OR The cast to value type 'Int32' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type Solution: Put conversion on values before putting it in functions like Avg, Sum etc like: In below code we have put conversion to decimal in average function.
var res =(from profile in dbModel.ProfileMasters
                                         select new
                                         {
                                             ProfileID = profile.ProfileId,
                                             Profile = profile.ClientName,
                                             Tasks= profile.TaskMasters.Count(),
                                             AverageTime = profile.TaskMasters.Select(x => EntityFunctions.DiffMinutes(x.StartTime, x.EndTime)).Average(y => (decimal?)y.Value),
                                             LastTime = profile.TaskMasters.Max(x=>x.StartTime)
                                         }).ToList();

Share This!


4 comments:

Unknown said...

I believe there are many more pleasurable opportunities ahead for individuals that looked at your site. Dotnet developer
Authorized Dot Net training in chennai

Anonymous said...

I'm not sure ezactly why but this weblog is loading very slow for me.
Is anyone else having this problem or is it a issue on my end?
I'll check back later on and see if the problem still exists.

Anonymous said...

What's up, always i used to check weblog posts here ezrly in the morning, for the reason that i
enjoy to learn more and more.

Anonymous said...

I'd like to find out more? I'd love to find out more details.

Powered By Blogger · Designed By Seo Blogger Templates