2014-06-19 2 views
1

EF Code First Approach를 사용하여 C#으로 WinForm 응용 프로그램을 개발하고 있습니다. 내가 가진 문제는 문자열을 사용하여 Enum을 연결하려고하는 linq 쿼리를 수행 할 때 발생합니다. 오류는 다음과 같습니다.linq 쿼리에서 문자열과 열거 형을 연결하십시오.

'Entities.VoucherType'형식을 'System.Object'형식으로 변환 할 수 없습니다. 엔티티에 LINQ는 원시적 인 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 
     }; 
+0

Entity Framework 4는 열거 형을 지원합니다. EF5는이 지원을 추가했습니다. –

+0

@SamLeach EF6.1을 사용 중입니다. – cristianqr

+0

좋아요, 버전 4 태그가 있습니다. 버전 6으로 변경했습니다. –

답변

1

당신이 하나의 시도 할 수를 :

var q = (from income in context.Incomes 
     join 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 
      };