c# - Concatenate a string and decimal in a Linq query -
i writing application in vs2010, framework 4.0, c# , silverlight 4.
i have simple class , linq query.
the class is:
public class pmdues { [key] public int duesid { get; set; } [datamember] public string dues_type { get; set; } public decimal dues_amount { get; set; } }
in domainservice have following iqueryable:
public iqueryable<pmdues> getdues() { return dues in objectcontext.tblduesrates orderby dues.due_type select new pmdues() { duesid = dues.id, dues_type = dues.due_type, dues_amount = dues.amount.value }; }
so far good.......but!
what want display dues_type + dues_amount concatenated. dues_amount declared decimal in sql server table. don't know , how concatenate dues_type dues_amount. tried following did not work. should concatenation in class? if how. still kind of new c#.
public iqueryable<pmdues> getdues() { return dues in objectcontext.tblduesrates orderby dues.due_type select new pmdues() { duesid = dues.id, dues_type = dues.due_type + " - " + dues.amount.value.tostring(), dues_amount = dues.amount.value }; }
thanks
use sqlfunctions.stringconvert
, found in system.data.entity.sqlserver
in ef6 (system.data.objects.sqlclient
in previous versions) in order convert decimal
string
:
dues_type = dues.due_type + " - " + sqlfunctions.stringconvert(dues.amount),
Comments
Post a Comment