我正在使用 EF Code First Approach 在 c# 中开发 WinForm 应用程序。我遇到的问题是当我执行 linq 查询时,尝试将 Enum 与字符串连接起来。错误如下:
无法将类型“Entities.VoucherType”转换为类型“System.Object”。LINQ to Entities 仅支持转换 EDM 基元或枚举类型
然后我显示枚举、POCO 实体和 linq 查询:
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
};