Thursday, November 6, 2014

Best Practices for Code Review


..http://support.smartbear.com/pdf/11_Best_Practices_for_Peer_Code_Review.pdf
Read More

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();

Read More

DbArithmeticExpression arguments must have a numeric common type


DbArithmeticExpression arguments must have a numeric common type Solution: we can't put datediff directly in linq / lambda.. instead of that we should use like : EntityFunctions.DiffMinutes Eg:
              dgvProfiles.DataSource = (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();
Read More
Powered By Blogger · Designed By Seo Blogger Templates