Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic + linq compilation error
    primarykey
    data
    text
    <p>I'll say up front that I am doing some really scary things with linq on dynamic data. But I can't figure out why this query fails to compile:</p> <p>Error 1 The property '&lt;>h__TransparentIdentifier0' cannot be used with type arguments</p> <pre> public class Program { public static void Main(string[] args) { var docs = new dynamic[0]; var q = from doc in docs where doc["@metadata"]["Raven-Entity-Name"] == "Cases" where doc.AssociatedEntities != null from entity in doc.AssociatedEntities where entity.Tags != null // COMPILER ERROR HERE from tag in entity.Tags where tag.ReferencedAggregate != null select new {tag.ReferencedAggregate.Id, doc.__document_id}; } } public static class LinqOnDynamic { private static IEnumerable&lt;dynamic&gt; Select(this object self) { if (self == null) yield break; if (self is IEnumerable == false || self is string) throw new InvalidOperationException("Attempted to enumerate over " + self.GetType().Name); foreach (var item in ((IEnumerable) self)) { yield return item; } } public static IEnumerable&lt;dynamic&gt; SelectMany(this object source, Func&lt;dynamic, int, IEnumerable&lt;dynamic&gt;&gt; collectionSelector, Func&lt;dynamic, dynamic, dynamic&gt; resultSelector) { return Enumerable.SelectMany(Select(source), collectionSelector, resultSelector); } public static IEnumerable&lt;dynamic&gt; SelectMany(this object source, Func&lt;dynamic, IEnumerable&lt;dynamic&gt;&gt; collectionSelector, Func&lt;dynamic, dynamic, dynamic&gt; resultSelector) { return Enumerable.SelectMany(Select(source), collectionSelector, resultSelector); } public static IEnumerable&lt;dynamic&gt; SelectMany(this object source, Func&lt;object, IEnumerable&lt;dynamic&gt;&gt; selector) { return Select(source).SelectMany&lt;object, object&gt;(selector); } public static IEnumerable&lt;dynamic&gt; SelectMany(this object source, Func&lt;object, int, IEnumerable&lt;dynamic&gt;&gt; selector) { return Select(source).SelectMany&lt;object, object&gt;(selector); } } </pre> <p>To add insult to injury, the following works:</p> <pre> var docs = new dynamic[0]; var q = from doc in docs where doc["@metadata"]["Raven-Entity-Name"] == "Cases" where doc.AssociatedEntities != null from entity in doc.AssociatedEntities where entity.Tags != null from tag in entity.Tags select new { tag.ReferencedAggregate.Id, doc.__document_id }; </pre> <p>It is only when I add:</p> <p>where tag.ReferencedAggregate != null</p> <p>That I get an error two lines before:</p> <p>where entity.Tags != null // COMPILER ERROR HERE</p> <p>Not sure what is going on</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload