Reputation: 19212
First off, I know this is a commonly asked question. But I cannot use other solutions because I am comparing types that cannot be delcared nullable types such as a DataRow type in my ternary operator. I also cannot format currency in my grid because I am pivoting my data and must have autogenerate columns set to true. I also cannot format currency somewhere else because I want one call to get the raw data and formatting to occur where is should. I need to use LinqSql because that is how I am preparing the data before binding it to a Telerik RadGrid
var drResults = from t1 in DatesTable.AsEnumerable()
join t2 in dtResult.AsEnumerable() on t1["MONTH_YEAR"] equals t2["MONTH_YEAR"] into t1_t2
from t2 in t1_t2.DefaultIfEmpty()
select new
{
MONTH_YEAR = t1.Field<string>("MONTH_YEAR"),
Appraisal_Fees = t2 != null ? String.Format("{0:C}", t2.Field<decimal>("AppraisalFees")) : 0): 0
};
Upvotes: 0
Views: 2851
Reputation: 837916
Try moving the ternary expression inside the argement to String.Format
.
String.Format("{0:C}", (t2 != null ? t2.Field<decimal>("AppraisalFees") : 0M))
You could also make it easier to read by writing it on two lines:
decimal appraisalFees = (t2 != null ? t2.Field<decimal>("AppraisalFees") : 0M);
Appraisal_Fees = String.Format("{0:C}", appraisalFees);
Upvotes: 1