2012-01-26 9 views
7

que tiene un tipo de enumeración llamada StatusTypesmiembro del tipo especificado no está soportado en LINQ a Entidades

public enum StatusTypes 
{ 
    Open = 1, 
    Allocated = 2, 
    WorkInProgress = 3, 
    WaitingOnRequestor = 4, 
    WaitingOnThirdParty = 5, 
    Monitoring = 6, 
    Testing = 7, 
    OnHold = 8, 
    Complete = 9, 
    SignedOff = 10, 
    Reopened = 11 
} 

Estoy tratando de utilizar esto en mi repositorio ....

public IQueryable<Incident> GetAllOutstandingIncidents() 
{ 
    return from i in db.Incidents 
       where i.Status != Types.StatusTypes.SignedOff && i.Status != Types.StatusTypes.Complete && i.DeletedDateTime != null 
       orderby i.DueDateTime 
       select i; 
    } 

... y luego usarlo en mi opinión ...

<tbody> 
    <% foreach (var incident in Model.TotalIncidentsOutstandingList) { %> 
       <tr> 
        <td><%: incident.IncidentID %></td> 
        <td><%: incident.Caller.NetworkName %></td> 
        <td><%: incident.Title %></td> 
        <td><%: incident.Service.Title %>/<%: incident.Category.Title %> <% if (incident.Subcategory != null) { %>/<%: incident.Subcategory.Title %><% } %></td> 
        <td><%: incident.Priority %></td> 
        <td></td> 
        <td><%: incident.AllocatedTo %></td> 
        <td><%: incident.DueDateTime %></td> 
       </tr> 
      <% } %> 
     </tbody> 

... pero yo estoy recibiendo el error "que el miembro de tipo especificado 'Estado' no es compatible con LINQ a Ent itias. Sólo inicializadores, miembros de la entidad, y las propiedades de navegación entidad son compatibles."

Cualquier ayuda agradecido recibió!

actualizará para mostrar incident.cs

public class Incident 
{ 
    public int IncidentID { get; set; } 
    public DomainUser Caller { get; set; } 

    [Display(Name = "Caller Type")] 
    public Types.CallerTypes CallerType { get; set; } 

    public Service Service { get; set; } 
    public Category Category { get; set; } 
    public Subcategory Subcategory { get; set; } 
    public string Title { get; set; } 

    [Display(Name = "Problem Description")] 
    public string ProblemDescription { get; set; } 

    public Equipment Equipment { get; set; } 

    public Types.ImpactTypes Impact { get; set; } 
    public Types.UrgencyTypes Urgency { get; set; } 

    [Display(Name = "Priority")] 
    public Types.PriorityTypes Priority { get; set; } 

    [Display(Name="Estimated time for completion")] 
    public DateTime? DueDateTime { get; set; } 

    [Display(Name="Date/Time")] 
    public DateTime? CreatedDateTime { get; set; } 
    public DomainUser CreatedBy { get; set; } 

    [Display(Name = "Allocated To")] 
    public HelpDeskMember AllocatedTo { get; set; } 
    public DateTime? AllocatedDateTime { get; set; } 

    public DateTime? ClosedDateTime { get; set; } 
    public int? ClosedBy { get; set; } 

    public DateTime? ReopenedDateTime { get; set; } 
    public int? ReopenedBy { get; set; } 

    public DateTime? DeletedDateTime { get; set; } 
    public HelpDeskMember DeletedBy { get; set; } 

    public Decimal? EstimatedInternalCost { get; set; } 
    public Decimal? EstimatedResources { get; set; } 
    public Decimal? RealInternalCost { get; set; } 
    public Decimal? EstimatedExternalCost { get; set; } 
    public Decimal? RealExternalCost { get; set; } 
    public Decimal? EstimatedTotalCost { get; set; } 
    public Decimal? RealTotalCost { get; set; } 

    public string CostCode { get; set; } 

    public string TimeRequired { get; set; } 
    public string ActualTimeTaken { get; set; } 

    public Types.StatusTypes Status { get; set; } 

    public string Solution { get; set; } 

    public bool UserSignedOff { get; set; } 

    public bool OverdueEmailSent { get; set; } 
    public bool EscalatedEmailSent { get; set; } 

    public ICollection<Note> Notes { get; set; } 
    public ICollection<Attachment> Attachments { get; set; } 
    public ICollection<HistoryItem> History { get; set; } 

    public Incident() 
    { 
     Notes = new List<Note>(); 
     Attachments = new List<Attachment>(); 
     History = new List<HistoryItem>(); 
    } 
} 
+0

¿Qué tipo tiene su propiedad 'Status'? Si es 'int', obtendrá un error de tiempo de compilación. Si es 'enum' tiene que convertir ambas partes de la condición de iguales en' int' – WarHog

+0

Hola @WarHog, la propiedad 'Status' tiene un tipo' Types.StatusTypes' que es un tipo 'enum'. ¿Podría darme un ejemplo de cómo lanzo ambas partes a 'int' por favor? Gracias. –

+0

¿Podemos ver su clase de Incidente? – NinjaNye

Respuesta

6

Como ya he dicho intente lanzar ambas partes al int tipo

public IQueryable<Incident> GetAllOutstandingIncidents() 
{ 
    return from i in db.Incidents 
     where (int)i.Status != (int)Types.StatusTypes.SignedOff 
      && (int)i.Status != (int)Types.StatusTypes.Complete 
      && i.DeletedDateTime != null 
     orderby i.DueDateTime 
     select i; 
} 

ACTUALIZACIÓN

Esa es una característica del Código de Primera. Deberías hacer lo siguiente. Cambiar su clase para:

[Column("Status", TypeName = "int")] 
public int InternalStatus { get; set; } 
public StatusTypes Status { get; set; } 

Y el uso siguiente consulta:

context.Incidents.Where(i => i.InternalStatus == (int)StatusTypes.Allocated); 

que he encontrado esta información here

+0

Gracias para publicar un ejemplo. Desafortunadamente, esto no resuelve este error. –

+0

Hay una solución - He actualizado mi publicación – WarHog

+0

Parece haberlo hecho. Gracias. –

1

probar este lugar

return from i in db.Incidents 
       where i.Status != (int)Types.StatusTypes.SignedOff && i.Status != (int)Types.StatusTypes.Complete && i.DeletedDateTime != null 
       orderby i.DueDateTime 
       select i; 
+0

Hola @Greco, gracias por la respuesta. Lo he intentado y obtengo "Operator '! =' No se puede aplicar a operandos de tipo 'Cognito.Models.Types'.StatusTypes 'y' int '" –

+0

ah, entonces intente lo siguiente: int signedOff = (int) Types.StatusTypes.SignedOff; int complete = (int) Types.StatusTypes.Complete; y luego use las variables locales en su consulta –

1

En su clase de incidente:

private int statusId; 
public Types.StatusTypes Status 
{ 
    get 
    { 
     return (Types.StatusTypes)statusId; 
    } 
    set 
    { 
     statusId = (int)value; 
    } 
} 

public Int StatusId 
{ 
    get 
    { 
     return statusId; 
    } 
} 

Luego, en que método:

public IQueryable<Incident> GetAllOutstandingIncidents() 
{ 
    int signedOffStatusType = (int)Types.StatusTypes.SignedOff;  
    int completeStatusType = (int)Types.StatusTypes.Complete; 

    return from i in db.Incidents 
      where i.StatusId != signedOffStatusType 
       && i.StatusId != completeStatusType 
       && i.DeletedDateTime != null 
     orderby i.DueDateTime 
     select i; 
} 

O utilizando el método de sintaxis:

public IQueryable<Incident> GetAllOutstandingIncidents() 
{ 
    int signedOffStatusType = (int)Types.StatusTypes.SignedOff;  
    int completeStatusType = (int)Types.StatusTypes.Complete; 

    return db.Incidents.Where(i => i.StatusId != signedOffStatusType 
           && i.StatusId != completeStatusType 
           && i.DeletedDateTime != null) 
         .OrderBy(i => i.DueDateTime); 
} 
+0

Gracias. Intenté eso. Todavía no tengo suerte, me temo! –

+0

¿Está usando el código primero? ¿Podemos ver su clase de incidente ... ah acabo de ver eso, ta – NinjaNye

+0

Sí, utilizando el código EF primero. Acabo de publicarlo ... –

4

También puede convertir a LINQ To Objeto con .AsEnumerable():

public IQueryable<Incident> GetAllOutstandingIncidents() 
{ 
    return from i in db.Incidents.AsEnumerable() 
       where i.Status != Types.StatusTypes.SignedOff && i.Status != Types.StatusTypes.Complete && i.DeletedDateTime != null 
       orderby i.DueDateTime 
       select i; 
} 

Dependiendo de lo que quiere, puede ser un no tan buena Solución: en lugar de simplemente extraer un objeto de la base de datos, extraerá todos los objetos cuando llame .AsEnumerable().

Cuestiones relacionadas