score:1

Accepted answer

You can't perform TryParse on the Sql server, but if you are not doing further selection criteria, then you can try pulling the data from Sql as it is and then parsing on the client.

eg

myresults = myDataContext.myDbFunction()
double note;

var list =(from a in myresults
select new 
{
   a.id,
   a.nom,
   a.prenom,
   a.moyenne,
}).ToList();


var finalResults = (from a in list 

select new MainReportModel()
{
   Id = a.id,
   Lastname = a.nom,
   Firstname = a.prenom,
   Average = a.moyenne,
   Result = double.TryParse(a.moyenne.Trim(), NumberStyles.Number,    CultureInfo.InvariantCulture, out note) ? (double.Parse(a.moyenne.Trim(), NumberStyles.Number, CultureInfo.InvariantCulture) < 4 ? "failed" : "success") : a.moyenne
}

score:0

Why don't you use TryParse at second one also?

Result = double.TryParse(a.moyenne.Trim(), NumberStyles. Number, CultureInfo.InvariantCulture, out note) ? (double.TryParse(a.moyenne.Trim(), NumberStyles.Number, CultureInfo.InvariantCulture) < 4 ? "failed" : "success") : a.moyenne

Try that.


Related Articles