本文介绍了错误:“联合或Concat中的类型不能用层次结构构造”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有人看到过这个错误吗? "System.NotSupportedException:Union或Concat中的类型不能使用层次结构构造。"在下面的代码的最后一行抛出错误。Anybody seen this error? "System.NotSupportedException: Types in Union or Concat cannot be constructed with hierarchy." Error thrown on the last line of code below. 这是我试图做的...... Here's what I was trying to do... var query = 来自 serviceTicket in db.ServiceTickets var query = from serviceTicket in db.ServiceTickets 加入 serviceRecord in db.ServiceRecords join serviceRecord in db.ServiceRecords on serviceTicket equals serviceRecord.ServiceTicket into serviceTicketServiceRecords on serviceTicket equals serviceRecord.ServiceTicket into serviceTicketServiceRecords from serviceRecord in serviceTicketServiceRecords from serviceRecord in serviceTicketServiceRecords 选择 new select new { SN = serviceTicket.Equipment.SN,SN = serviceTicket.Equipment.SN, JCN = serviceTicket.JCN,JCN = serviceTicket.JCN, JCNStartDate =( DateTime ?)serviceTicket.JCNStartDate,JCNStartDate = (DateTime?)serviceTicket.JCNStartDate, DisplayedProblemCode = serviceTicket.DisplayedProblemCode == null ? String .Empty:serviceTicket.DisplayedProblemCode。 CodeAndDescription,DisplayedProblemCode = serviceTicket.DisplayedProblemCode == null ? String.Empty : serviceTicket.DisplayedProblemCode.CodeAndDescription, CauseCode = serviceRecord.CauseCode == null ? 字符串 .Empty:serviceRecord.CauseCode。 CodeAndDescription,CauseCode = serviceRecord.CauseCode == null ? String.Empty : serviceRecord.CauseCode.CodeAndDescription, ActionCode = serviceRecord.ActionCode == null ? String .Empty:serviceRecord.ActionCode。 CodeAndDescription,ActionCode = serviceRecord.ActionCode == null ? String.Empty : serviceRecord.ActionCode.CodeAndDescription, FailureCode = serviceRecord.FailureCode == null ? 字符串 .Empty:serviceRecord.FailureCode。 CodeAndDescription,FailureCode = serviceRecord.FailureCode == null ? String.Empty : serviceRecord.FailureCode.CodeAndDescription, Status = serviceRecord.Status.Name,Status = serviceRecord.Status.Name, StartTime =( DateTime ?)serviceRecord.StartTime,StartTime = (DateTime?)serviceRecord.StartTime, EndTime =( DateTime ?)serviceRecord.EndTime,EndTime = (DateTime?)serviceRecord.EndTime, ServiceRecordParts = serviceRecord.ServiceRecordParts,ServiceRecordParts = serviceRecord.ServiceRecordParts, Notes = serviceRecord.Notes Notes = serviceRecord.Notes}; var ticketQuery = from serviceTicket in db.ServiceTickets var ticketQuery = from serviceTicket in db.ServiceTickets 选择 new select new { SN = serviceTicket.Equipment.SN,SN = serviceTicket.Equipment.SN, JCN = serviceTicket.JCN,JCN = serviceTicket.JCN, JCNStartDate =( DateTime ?)serviceTicket.JCNStartDate,JCNStartDate = (DateTime?)serviceTicket.JCNStartDate, DisplayedProblemCode = serviceTicket.DisplayedProblemCode == null ? String .Empty:serviceTicket.DisplayedProblemCode。 CodeAndDescription,DisplayedProblemCode = serviceTicket.DisplayedProblemCode == null ? String.Empty : serviceTicket.DisplayedProblemCode.CodeAndDescription, CauseCode = String .Empty,CauseCode = String.Empty, ActionCode = 字符串 .Empty,ActionCode = String.Empty, FailureCode = 字符串 .Empty,FailureCode = String.Empty, Status = serviceTicket.InitialStatus.Name,Status = serviceTicket.InitialStatus.Name, StartTime =( DateTime ?)serviceTicket.JCNStartDate,StartTime = (DateTime?)serviceTicket.JCNStartDate, EndTime =( DateTime ?) null ,EndTime = (DateTime?)null, ServiceRecordParts =( EntitySet < ServiceRecordPart >) null ,ServiceRecordParts = (EntitySet<ServiceRecordPart>)null,备注= serviceTicket.Notes Notes = serviceTicket.Notes}; if ( HttpContext .Current.Request.QueryString [ "StartDate" ]!= null )if (HttpContext.Current.Request.QueryString["StartDate"] != null) query = query.Where(serviceRecord => serviceRecord.StartTime> = DateTime 。解析( HttpContext .Current.Request。 QueryString [ " StartDate" ]) ); query = query.Where(serviceRecord => serviceRecord.StartTime >= DateTime.Parse(HttpContext.Current.Request.QueryString["StartDate"])); if ( HttpContext .Current.Request.QueryString [ " EndDate" ]!= null ) if (HttpContext.Current.Request.QueryString["EndDate"] != null) query = query.Where(serviceRecord => serviceRecord.StartTime< = DateTime .Parse( HttpContext .Current.Request.QueryString [ " EndDate" ])); query = query.Where(serviceRecord => serviceRecord.StartTime <= DateTime.Parse(HttpContext.Current.Request.QueryString["EndDate"])); query = query.Union(ticketQuery); query = query.Union(ticketQuery); query = query。 OrderBy(p => p.SN); query = query.OrderBy(p => p.SN); LINQGeneratedResultsLiteral.Text = query.Count()。ToString(); LINQGeneratedResultsLiteral.Text = query.Count().ToString();推荐答案 ServiceRecordParts = serviceRecord.ServiceRecordParts,ServiceRecordParts = serviceRecord.ServiceRecordParts, Notes = serviceRecord.Notes Notes = serviceRecord.Notes 我的建议是做结束,没有匿名类型,没有var。这将使问题更加清晰。My recommendation is to do it over, without anonymous types and without var. This will make the problem more clear. 这篇关于错误:“联合或Concat中的类型不能用层次结构构造”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-14 09:20