Sunday, 15 September 2013

c# - LINQ: "Types in Union or Concat are constructed incompatibly." -


I'm relatively new to ASP.NET and LINQ but I had to face a very strange behavior that was almost crazy about me. I found some discussions about the aforementioned error in the title, but my problem was not there to fix Take a look at the snapshot of object relational designer:

 Screenshot from ORD, showing the data model

As you can see, enter a relationship is for the connection of anchor s, so the table for this is relationship : relation.AnchorIDFrom = & gt; There are two foreign keys defined for Anchor. EncoreID and relationship. Encrypta = & gt; Anchor.AnchorID . None of those columns is empty. My goal is now, a list of anchors ID has been given, take part in these anchors to retrieve all relation s. Also here is the method:

  [WebMethod] public string GetRelations (string token, List & lt; Guid & gt; anchorIDs) {JavaScript Serializer js = new JavaScriptSerializer (); LinkItCoreDataContext DC = New LinkItCoreDataContext (); IQueryable anchor relationQry = dc.Anchors where anchorIDs.Contains (anchor.AnchorID) // stupid name because the object does not support Relational Designer // custom names to select the connection anchor.Relations.Union (anchor.Relations1) New {RelationID = relation.RelationID, anchorIDFrom = relation.AnchorIDFrom, anchorIDTo = relation.AnchorIDTo, relationTypes = in relation to type. RelationTypes // Fooled name again: choose the type. RelationType1}; Return js.Serialize (relationQry); Where the error occurs // here}   

Runtime it gives me a NotSupportedException stating Union or in Concat inconvenient as are building I think it's quite funny, because the expression anchor.Relations.Union (anchor.Relations1) completely the same as a must have two things merge a syntax Are there. If I change the important row to an anchor in relation to Relationship to or in relation to the anchor. Reference 1 Everything works well, besides adding toList () (which is sometimes referred to as a solution) will not change anything.

What am I missing?

I have tried a similar case and received the same error, while the same in the unit framework The query runs fine. So I think that you are running a bug here (or an "unsupported feature") and you may have to work around it. You can do that by changing around the questions:

  on relationQry = anchor.Relations in relation to where anchorIDs.Contains (relation.AnchorIDTo) || anchorIDs.Contains (relation.AnchorIDFrom) new selection {relationID = relation.RelationID, anchorIDFrom = relation.AnchorIDFrom, anchorIDTo = relation.AnchorIDTo, relationTypes = type.RelationType1 selection} of type relation.RelationTypes;   

By the way:. You can change the "idiot name" :) by selecting the name of the property in the designer and its child.

No comments:

Post a Comment