का उपयोग करके मैं डैपर का उपयोग एक कॉलम में 2 कॉलम परिणाम प्राप्त करने के लिए कर रहा हूं। मैंने देखा है कि IntelliSense मुझे एक .ToDictionary() से पता चलता है जब मैं resultset पर ले जाएं, लेकिन मैं के बाद से व्यवसायिक गतिशील गुण का उपयोग करता है यह काम करने के लिए नहीं मिल सकता है/expandoObjectशब्दकोश को बदलने के लिए <गतिशील, गतिशील> शब्दकोश शब्दकोश <string, string> Colllection.ToDictionary()
Dictionary<string, string > rowsFromTableDict = new Dictionary<string, string>();
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
var results = connection.Query
("SELECT col1 AS StudentID, col2 AS Studentname
FROM Student order by StudentID");
if (results != null)
{
//how to eliminate below foreach using results.ToDictionary()
//Note that this is results<dynamic, dynamic>
foreach (var row in results)
{
rowsFromTableDict.Add(row.StudentID, row.StudentName);
}
return rowsFromTableDict;
}
}
धन्यवाद
हां परिवर्तित नहीं कर सकता। उसने ऐसा किया। 'गतिशील' से बाहर निकलने के लिए याद रखने के लिए धन्यवाद – Gullu
+1। –
गतिशील अच्छा है, लेकिन इसमें बहुत सारे जाल हैं जैसे कि स्थिर प्रकारों पर वापस जाने की आवश्यकता है। –