LINQ中不支持实体指定类型的成员 [英] Specified type member not supported in LINQ to Entities
问题描述
我有一个名为StatusTypes枚举类型
公开枚举StatusTypes
{
开放= 1,
分配= 2,
WorkInProgress = 3,
WaitingOnRequestor = 4,
WaitingOnThirdParty = 5,
监控= 6,
测试= 7,
保留状态= 8,
完整= 9,
SignedOff = 10,
重新= 11
}
我想在我的仓库使用这个....
公开的IQueryable<事件与GT; GetAllOutstandingIncidents()
{
从我在db.Incidents返回
其中,i.Status = Types.StatusTypes.SignedOff和放大器;!&安培; i.Status = Types.StatusTypes.Complete和放大器;!&安培; i.DeletedDateTime!= NULL
排序依据i.DueDateTime
选择我;
}
...然后用它在我看来......
<&TBODY GT;
<%的foreach(VAR事件Model.TotalIncidentsOutstandingList){%GT;
&所述; TR>
&所述; TD>&下;%:incident.IncidentID%GT;&下; / TD>
&所述; TD>&下;%:incident.Caller.NetworkName%GT;&下; / TD>
&所述; TD>&下;%:incident.Title%GT;&下; / TD>
&所述; TD>&下;%:incident.Service.Title%GT; /<%:incident.Category.Title%GT; <如果%(!incident.Subcategory = NULL){%GT; /<%:incident.Subcategory.Title%GT;&下;%}%GT;&下; / TD>
&所述; TD>&下;%:incident.Priority%GT;&下; / TD>
< TD>< / TD>
&所述; TD>&下;%:incident.AllocatedTo%GT;&下; / TD>
&所述; TD>&下;%:incident.DueDateTime%GT;&下; / TD>
< / TR>
<%}%GT;
< / TBODY>
...但我得到的错误是指定类型的成员'状态'不是在LINQ支持实体只有初始化,实体成员和实体导航属性都支持。
任何帮助感激地接受!
更新,以显示incident.cs
公共类事件
{
公众诠释IncidentID {搞定;组; }
公共DomainUser来电{搞定;组; } [显示(NAME =来电类型)
公共Types.CallerTypes CallerType {搞定;组; } 公共服务服务{搞定;组; }
公众分类分类{搞定;组; }
公共子目录子目录{搞定;组; }
公共字符串名称{搞定;组; } [显示(NAME =问题说明)]
公共字符串ProblemDescription {搞定;组; } 公共设备设备{搞定;组; } 公共Types.ImpactTypes影响{搞定;组; }
公共Types.UrgencyTypes紧急{搞定;组; } [显示(名称=优先级)]
公共Types.PriorityTypes优先{搞定;组; } [显示(NAME =估计时间完成)]
公众的DateTime? DueDateTime {搞定;组; } [显示(NAME =日期/时间)]
公众的DateTime? CreatedDateTime {搞定;组; }
公共DomainUser CreatedBy {搞定;组; } [显示(NAME =分配到)]
公共HelpDeskMember AllocatedTo {搞定;组; }
公众的DateTime? AllocatedDateTime {搞定;组; } 公众的DateTime? ClosedDateTime {搞定;组; }
公众诠释? ClosedBy {搞定;组; } 公众的DateTime? ReopenedDateTime {搞定;组; }
公众诠释? ReopenedBy {搞定;组; } 公众的DateTime? DeletedDateTime {搞定;组; }
公共HelpDeskMember DeletedBy {搞定;组; } 公共小数? EstimatedInternalCost {搞定;组; }
公共小数? EstimatedResources {搞定;组; }
公共小数? RealInternalCost {搞定;组; }
公共小数? EstimatedExternalCost {搞定;组; }
公共小数? RealExternalCost {搞定;组; }
公共小数? EstimatedTotalCost {搞定;组; }
公共小数? RealTotalCost {搞定;组; } 公共字符串成本code {搞定;组; } 公共字符串TimeRequired {搞定;组; }
公共字符串ActualTimeTaken {搞定;组; } 公共Types.StatusTypes状态{搞定;组; } 公共字符串解决方案{搞定;组; } 公共BOOL UserSignedOff {搞定;组; } 公共BOOL OverdueEmailSent {搞定;组; }
公共BOOL EscalatedEmailSent {搞定;组; } 公众的ICollection<注意>注意{搞定;组; }
公众的ICollection<&附件GT;附件{搞定;组; }
公众的ICollection< HistoryItem>历史{搞定;组; } 突发公共事件()
{
注=新的List<注意>();
附件=新的List<&附件GT;();
记录=新的List< HistoryItem>();
}
}
正如我已经说过尝试这两部分转换为 INT
键入
公开的IQueryable<事件与GT; GetAllOutstandingIncidents()
{
从我在db.Incidents返回
其中,(int)的i.Status!=(int)的Types.StatusTypes.SignedOff
&功放;&安培; (INT)i.Status!=(int)的Types.StatusTypes.Complete
&功放;&安培; i.DeletedDateTime!= NULL
排序依据i.DueDateTime
选择我;
}
更新
这是code首先的一个特点。你应该做以下几点。更改您的类,以便:
[专栏(状态,类型名=INT)]
公众诠释InternalStatus {搞定;组; }
公共StatusTypes状态{搞定;组; }
和使用以下查询:
context.Incidents.Where(I => i.InternalStatus ==(INT)StatusTypes.Allocated);
我发现这个信息<一个href=\"http://nadege.deroussen.net/ef-the-specified-type-member-property-is-not-supported-in-linq-to-entities\">here
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>();
}
}
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;
}
UPDATE
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; }
And use following query:
context.Incidents.Where(i => i.InternalStatus == (int)StatusTypes.Allocated);
I've found this info here
这篇关于LINQ中不支持实体指定类型的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!