I'm developing a WinForm application in c# with EF Code First Approach. The problem I have is when I do a linq query where a try to concat an Enum with a string. The error is as follows:
Unable to cast the type 'Entities.VoucherType' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types
Then I show the Enum, POCO Entities and linq query:
public enum VoucherType
{
FAC = 1,
BV,
TKT,
GR
}
public partial class Order
{
public int OrderId { get; set; }
public VoucherType VoucherType { get; set; }
public string VoucherSeries { get; set; }
public string VoucherNumber { get; set; }
}
public partial class Income
{
public int IncomeId { get; set; }
public int OrderId { get; set; }
public decimal IncomeAmount { get; set; }
}
var q = from income in context.Incomes
join order in context.Orders on income.OrderId equals order.OrderId
select new
{
Voucher = order.VoucherType + "-" + order.VoucherSeries + "-" + order.VoucherNumber,
Amount = income.IncomeAmount
};