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.
Source: stackoverflow.com
Related Query
- C# string to number, TryParse returns true when Parse fails
- Linq to SQL .Equals returns true when comparing int to string --> Id.Equals("5") returns true
- XDocument.Element returns null when parsing an xml string
- LINQ query returns old results when source list is re-initialized
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Regex for extract URL from string fails when string contains multiple double quotes?
- LINQ returns wrong number of items when DataLoadOptions is set
- .Any() with Nullables - Returns False When I Expect True
- How can I query a database with LINQ when the column is a number but I have a string in the WHERE?
- How can I create multiple XML files in C# when a stored procedure that is called returns a large number of rows?
- List or Array of String Contain specific word in Html Source Code
- LINQ Query returns false when it should be true
- How do I sort strings alphabetically while accounting for value when a string is numeric?
- C# - code to order by a property using the property name as a string
- Number of occurrences of a character in a string
- Check if a string has at least one number in it using LINQ
- Entity-framework code is slow when using Include() many times
- Explicit/implicit cast operator fails when using LINQ's .Cast() operator
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- Parse string to C# lambda Func
- Entity Framework Skip/Take is very slow when number to skip is big
- EF Query using .Contains() and .ToLowerInvariant() Results in no matches when match is found at the end of a string
- This code returns distinct values. However, what I want is to return a strongly typed collection as opposed to an anonymous type
- Is there an easy way to parse a (lambda expression) string into an Action delegate?
- LINQ new instance when SingleOrDefault returns null
- Using LINQ to parse the numbers from a string
- Parse string into a LINQ query
- Check if a String value contains any number by using Lambda Expression
- How can I sort a string of text followed by a number using LINQ
- Return an empty collection when Linq where returns nothing
More Query from same tag
- Is there a list to compare the properties of items between two lists?
- How to use SQL Server table hints while using LINQ?
- How to select greater number and lower number using LINQ To SQL in C#
- Expose Foreign key through fluent API
- LINQ query to search multiple conditions in a specific order?
- Getting the list
- Linq left join into new object
- How do multi-parameter linq expression initialize their parameter?
- How to provide default values in select clause of a query in LINQ to NHibernate
- Refactor method (C#)
- Attaching an object to another context in EF 4
- Linq: how to get values of second level nodes
- LINQ - Group by one column and Count() rows (extension method)
- Condition if list exists inside list
- LINQ IQueryable with List<string> input parameter
- What is the use of the first parameter in HTML.DropDownListFor?
- LINQ: How to null out properties in a projection?
- Most efficient collection for storing data from LINQ to Entities?
- Efficient way to loop through data to return Object in Web api c#
- How to implement "where" clause in linq
- Filtering data by LINQ to SQL
- linq projection element count
- Best Linq Syntax for Adding Objects of a class to a List of a Base Class
- Is there any way to get Linq-to-entities to evaluate a local expression
- LinqToSql query execution timing
- How to tell LINQ providers about version/type of SQL Server before hand?
- Add new lambda expressions using Expression Tree
- Unite two properties into plain list c#
- compare same data into table and delete different data by : Linq
- From "LINQ to SQL" to "Azure Table Storage" or "SQL Data Service"