【发布时间】:2014-06-19 15:07:19
【问题描述】:
我正在使用 EF 代码优先方法在 c# 中开发 WinForm 应用程序。我遇到的问题是当我执行 linq 查询时,尝试将 Enum 与字符串连接起来。错误如下:
无法将类型“Entities.VoucherType”转换为类型“System.Object”。 LINQ to Entities 仅支持转换 EDM 基元或枚举类型
然后我显示 Enum、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
};
【问题讨论】:
-
Entity Framework 4 不支持枚举。 EF5 添加了此支持。
-
@SamLeach 我正在使用 EF6.1
-
好的,你已经标记了 version4。我已将其更改为版本 6。
标签: c# linq entity-framework-6.1