LINQ to Entities不支持指定类型的成员 [英] Specified type member not supported in LINQ to Entities

查看:576
本文介绍了LINQ to Entities不支持指定类型的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为StatusTypes的枚举类型

I have an enum type called StatusTypes

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
}

我试图在我的存储库中使用这个。

I'm trying to use this in my repository....

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;
    }

...然后在我的视图中使用...

...and then use it in my view...

<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>

...但是我收到错误指定的类型成员状态不受支持在LINQ to Entities中,只支持初始化器,实体成员和实体导航属性。

... but I'm getting the error "The specified type member 'Status' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."

任何帮助感谢!

更新显示事件.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>();
    }
}


推荐答案

我已经说过,试图把这两部分分别转到 int 类型

As I've already said try to cast both part to the int type

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;
}

更新

这是Code First的一个功能。你应该做以下。改变你的班级:

That's a feature of Code First. You should do following. Change your class so:

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

并使用以下查询:

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

我找到了这个信息 here

这篇关于LINQ to Entities不支持指定类型的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆