LINQ to Entities 不支持指定的类型成员
我有一个名为 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
}
我试图在我的存储库中使用它......
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;
}
然后在我的视图中使用它......
<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 不支持 Status',仅支持初始值设定项、实体成员和实体导航属性。”
任何帮助感激不尽!
更新以显示 event.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>();
}
}
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>
... 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."
Any help gratefully received!
UPDATE TO SHOW 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>();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如我已经说过的,尝试将两个部分都转换为
int
类型UPDATE
这是 Code First 的一个功能。你应该做以下事情。更改您的课程:
并使用以下查询:
我找到了此信息 此处
As I've already said try to cast both part to the
int
typeUPDATE
That's a feature of Code First. You should do following. Change your class so:
And use following query:
I've found this info here
您还可以使用 .AsEnumerable() 转换为 LINQ To Object:
根据您的需要,这可能是一个不太好的解决方案:当您调用 .AsEnumerable( 时,它不会只从数据库中提取一个对象,而是会提取所有对象)。
You can also convert to LINQ To Object with .AsEnumerable():
Depending of what you want, it could be a not so good solution: Instead of just pulling one object from the database, it will pull all objects when you call .AsEnumerable().
试试这个
Try this instead
在您的事件类中:
然后在您的方法中:
或使用方法语法:
In your Incident class:
Then in you method:
Or using method syntax: