C# LINQ to实体中不支持指定的类型成员
我有一个名为StatusTypes的枚举类型C# LINQ to实体中不支持指定的类型成员,c#,asp.net-mvc-3,enums,linq-to-entities,C#,Asp.net Mvc 3,Enums,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 =
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;
}
public IQueryable GetAllOutstandingIncidents()
{
从数据库中的i返回
其中i.Status!=Types.StatusTypes.SignedOff&&i.Status!=Types.StatusTypes.Complete&&i.DeletedDateTime!=null
orderby i.DueDateTime
选择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'。只支持初始值设定项、实体成员和实体导航属性。”
感谢您的帮助
更新以显示事件。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>();
}
}
公共类事件
{
public int IncidentID{get;set;}
公共域用户调用方{get;set;}
[显示(Name=“呼叫者类型”)]
public Types.CallerTypes CallerType{get;set;}
公共服务服务{get;set;}
公共类别{get;set;}
公共子类别子类别{get;set;}
公共字符串标题{get;set;}
[显示(Name=“问题描述”)]
公共字符串ProblemDescription{get;set;}
公共设备{get;set;}
public Types.ImpactTypes影响{get;set;}
public Types.UrgencyTypes{get;set;}
[显示(Name=“优先级”)]
public Types.prioritypes优先级{get;set;}
[显示(Name=“预计完成时间”)]
公共日期时间?DueDateTime{get;set;}
[显示(Name=“日期/时间”)]
公共日期时间?CreatedDateTime{get;set;}
公共域用户通过{get;set;}创建
[显示(Name=“分配给”)]
公共HelpDeskMember分配给{get;set;}
公共日期时间?AllocatedDateTime{get;set;}
公共日期时间?ClosedDateTime{get;set;}
公共int?通过{get;set;}关闭
公共日期时间?重新开始日期时间{get;set;}
公共int?通过{get;set;}重新打开
公共日期时间?删除日期时间{get;set;}
public HelpDeskMember DeletedBy{get;set;}
公共十进制?估计内部成本{get;set;}
公共十进制?估计数据源{get;set;}
公共十进制?RealInternalCost{get;set;}
公共十进制?EstimatedExternalCost{get;set;}
公共十进制?RealExternalCost{get;set;}
公共十进制?估计总成本{get;set;}
公共十进制?RealTotalCost{get;set;}
公共字符串成本代码{get;set;}
公共字符串TimeRequired{get;set;}
公共字符串ActualTimeTaken{get;set;}
public Types.StatusTypes状态{get;set;}
公共字符串解决方案{get;set;}
public bool UserSignedOff{get;set;}
public bool OverdueEmailSent{get;set;}
公共布尔发送{get;set;}
公共ICollection注释{get;set;}
公共ICollection附件{get;set;}
公共ICollection历史记录{get;set;}
公共事件()
{
注释=新列表();
附件=新列表();
历史=新列表();
}
}
试试这个
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;
正如我已经说过的,尝试将这两部分都转换为
int
类型
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;
}
并使用以下查询:
context.Incidents.Where(i => i.InternalStatus == (int)StatusTypes.Allocated);
我在您的事件类中找到了以下信息:
private int statusId;
public Types.StatusTypes Status
{
get
{
return (Types.StatusTypes)statusId;
}
set
{
statusId = (int)value;
}
}
public Int StatusId
{
get
{
return statusId;
}
}
然后在您的方法中:
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;
}
public IQueryable GetAllOutstandingIncidents()
{
int signedOffStatusType=(int)Types.StatusTypes.SignedOff;
int completeTastusType=(int)Types.StatusTypes.Complete;
从数据库中的i返回
其中i.StatusId!=signedOffStatusType
&&i.StatusId!=CompleteTastusType
&&i.DeletedDateTime!=null
orderby i.DueDateTime
选择i;
}
或使用方法语法:
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);
}
public IQueryable GetAllOutstandingIncidents()
{
int signedOffStatusType=(int)Types.StatusTypes.SignedOff;
int completeTastusType=(int)Types.StatusTypes.Complete;
返回db.events.Where(i=>i.StatusId!=signedOffStatusType
&&i.StatusId!=CompleteTastusType
&&i.DeletedDateTime!=null)
.OrderBy(i=>i.DueDateTime);
}
您还可以使用.AsEnumerable()将LINQ转换为对象:
public IQueryable GetAllOutstandingIncidents()
{
在db.Incidents.AsEnumerable()中从i返回
其中i.Status!=Types.StatusTypes.SignedOff&&i.Status!=Types.StatusTypes.Complete&&i.DeletedDateTime!=null
orderby i.DueDateTime
选择i;
}
根据您的需要,它可能不是一个很好的解决方案:当您调用.AsEnumerable()时,它将从数据库中提取所有对象,而不是仅提取一个对象。您的
Status
属性的类型是什么?如果它是int
,您将得到编译时错误。如果它是enum
您必须将equals条件的两部分强制转换为int
Hi@WarHog,则属性Status
具有类型Types.StatusTypes
这是enum
类型。你能给我一个例子,说明我是如何将两个部分都转换为int
的吗?谢谢。我们能看一下你的事故课吗?嗨@Greco,谢谢你的回复。我已经试过了,我得到了“Operator”!=“不能应用于”Cognito.Models.Types.StatusTypes“和”int“类型的操作数”噢,那么试试下面的方法:int-signedOff=(int)Types.StatusTypes.signedOff;int complete=(int)Types.StatusTypes.complete;然后使用查询库中的局部变量发布示例。不幸的是,这并不能解决这个错误。只是给我添加了这个作品。[列(“状态”,TypeName=“int”)]pub
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);
}
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;
}