我試圖從數據庫動態類型返回返回屬性的名稱屬性名稱:PetaPoco從動態類型
var d = mDataAccess.Single<dynamic>("select col1 = 'asd', col2 = 'qwe'");
object o = d;
var props = o.GetType().GetProperties();
int propsCount = props.Count();
的propsCount是0,但是我希望有2個, 在這種情況下,下面的代碼將返回給我兩個名字:col1和col2
List<string> names = o.GetType().GetProperties().Select(x => x.Name).ToList();
任何想法爲什麼我沒有得到我期望的屬性?
'(d as IDictionary)。Keys'返回null。也許我應該提到所有這些都發生在WCF中,但我認爲這沒有什麼區別。 –
Dmitry
我在想這個解決方案會經常工作,但是區別在於這個'dynamic d'變量是通過PetaPoco來自數據庫的。 – Dmitry
不應該有所作爲。當您將dynamic作爲類型參數時,它將返回ExpandoObject。 – Schotime