Monday, 15 July 2013

c# - Concat a enum with a string in a linq query -



c# - Concat a enum with a string in a linq query -

i'm developing winform application in c# ef code first approach. problem have when linq query seek concat enum string. error follows:

unable cast type 'entities.vouchertype' type 'system.object'. linq entities supports casting edm primitive or enumeration types

then show enum, poco entities , linq query:

class="lang-cs prettyprint-override">public enum vouchertype { fac = 1, bv, tkt, gr } class="lang-cs prettyprint-override">public partial class order { public int orderid { get; set; } public vouchertype vouchertype { get; set; } public string voucherseries { get; set; } public string vouchernumber { get; set; } } class="lang-cs prettyprint-override">public partial class income { public int incomeid { get; set; } public int orderid { get; set; } public decimal incomeamount { get; set; } } class="lang-cs prettyprint-override">var q = income in context.incomes bring together order in context.orders on income.orderid equals order.orderid select new { voucher = order.vouchertype + "-" + order.voucherseries + "-" + order.vouchernumber, amount = income.incomeamount };

you seek one:

var q = (from income in context.incomes bring together order in context.orders on income.orderid equals order.orderid select new { vouchertype = order.vouchertype, voucherseries = order.voucherseries, vouchernumber = order.vouchernumber, incomeamount = income.incomeamout }).asenumerable() .select(x=> new { voucher = x.vouchertype + "-" + x.voucherseries + "-" +x.vouchernumber, amount = x.incomeamount };

c# linq entity-framework-6.1

No comments:

Post a Comment