मैं आगे कहूंगा कि मैं गतिशील डेटा पर linq के साथ कुछ वाकई डरावनी चीजें कर रहा हूं। लेकिन मैं समझ नहीं क्यों इस क्वेरी को संकलित करने में विफल रहता है:गतिशील + linq संकलन त्रुटि
त्रुटि 1 संपत्ति '<> h__TransparentIdentifier0' प्रकार तर्क के साथ नहीं किया जा सकता
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<dynamic> 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<dynamic> SelectMany(this object source, Func<dynamic, int, IEnumerable<dynamic>> collectionSelector, Func<dynamic, dynamic, dynamic> resultSelector) { return Enumerable.SelectMany(Select(source), collectionSelector, resultSelector); } public static IEnumerable<dynamic> SelectMany(this object source, Func<dynamic, IEnumerable<dynamic>> collectionSelector, Func<dynamic, dynamic, dynamic> resultSelector) { return Enumerable.SelectMany(Select(source), collectionSelector, resultSelector); } public static IEnumerable<dynamic> SelectMany(this object source, Func<object, IEnumerable<dynamic>> selector) { return Select(source).SelectMany<object, object>(selector); } public static IEnumerable<dynamic> SelectMany(this object source, Func<object, int, IEnumerable<dynamic>> selector) { return Select(source).SelectMany<object, object>(selector); } }
चोट के अपमान जोड़ने के लिए, निम्न कार्य :
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 };
यह केवल जब मैं जोड़ने है:
जहां tag.ReferencedAggregate = अशक्त
मैं एक त्रुटि दो पंक्तियों मिल यही कारण है कि पहले:
जहां entity.Tags = अशक्त // कंपाइलर त्रुटि यहाँ
सुनिश्चित नहीं हैं कि
धन्यवाद, वह था। मैंने इकाई में टैग से का उपयोग करके इसे हल करना समाप्त कर दिया। टैग्स ((Func) (t => t.ReferencedAggregate! = Null)) नरक के रूप में बदसूरत। मैंने विस्तार विधि लिखने की कोशिश की, लेकिन मुझे पता नहीं लगा कि सीएससी इसे कैसे स्वीकार कर सकता है। –