c# - LINQ - ToString("N2") fails without exception? -



c# - LINQ - ToString("N2") fails without exception? -

the linq query below works fine without .tostring("n2") part. works fine using .tostring(). when adding ("n2") instead of () returns nil without raising exceptions. why?

workaround question: when printing fundfee numbers without formatting printed 9.00000000e-3. happens in linq queries, currentculture en-us. way alter non e-notation? 1 workaround utilize .tostring().substring(0,4) work since numbers between 0 , 1.

any other improvement ideas welcome too:)

list<fundstairitem> listfunds = (from fundinfoisin in amdw.fundsinfos.where(f => f.type == 1) fundinfoname in amdw.fundsinfos.where(f =>f.type == 2) fundfee in amdw.fundfees securities in amdw.securities securities.isin == fundinfoisin.value && fundinfoisin.value != null && fundinfoisin.portfolioid == fundinfoname.portfolioid && fundfee.isin == securities.isin select new fundstairitem { key = fundinfoisin.id, name = (fundinfoname.value != "" && fundinfoisin.value != "") ? fundinfoname.value + " " + fundfee.class.trim() + " ( fee: " + (fundfee.fee*100).tostring("n2") + "% , isin:" +fundinfoisin.value +")" : securities.name }).groupby(p=>p.key).select(g=>g.first()).tolist();

edit (added info comment):

adding before query: amdw.log = console.out gives output: a first chance exception of type 'system.notsupportedexception' occurred in system.data.linq.dll in console.

linq sql can't translate format strings t-sql.

instead of relying on sql server format string, fetch info need memory , project info right format there.

a simple, fictional example:

// don't - lts tries translate format string t-sql var formattedfundfeess = fund in context.funds select fund.fee.tostring("n2"); // - fetch fees memory , allow .net format var fundfeesinmemory = (from fund in context.funds select fund.fee).tolist(); var formattedfundfees = fundfee in fundfeesinmemory select fundfee.tostring("n2");

c# linq linq-to-sql

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -