You need to cast the ExpandoObject
to dynamic
:
xdoc.Descendants("database")
.Select(dbDetail =>
{
dynamic expandoObj = new ExpandoObject();
expandoObj.DBDetailId = Convert.ToInt32(dbDetail.Attribute("dbDetailId").Value);
expandoObj.DBServerId = Convert.ToInt32(dbDetail.Attribute("dbServerID").Value);
return (ExpandoObject) expandoObj;
})
.ToList();
Also you can cast ExpandoObject
to IDictionary<string, object>
:
var x = new ExpandoObject() as IDictionary<string, object>;
x.Add("DBDetailId", Convert.ToInt32(dbDetail.Attribute("dbDetailId").Value));
x.Add("DBServerId", Convert.ToInt32(dbDetail.Attribute("dbServerID").Value));