views:

59

answers:

0
var emp = from c in root.Descendants("Objects") // From Xml XDocument
                        select new
                        {
                            ObjType = (string)c.Element("ObjectType").Value, //Employee object
                            ID = (string)c.Element("ObjectID").Attribute("ID").Value                            
                        };


            foreach (var item in emp)                 {
                var obj1 = (IList<object>)current[item.ObjType];
                var IDCollection = obj1.AsQueryable().Select(string.Format("new({0})", item.ID));

            };

The runtime throws exception at .Select(string.Format("new({0})", item.ID)); .The runtime is not able to find the field "ID" value in the "object". When i explicitly cast

    var obj1 = (IList<object>)current[item.ObjType]; 
to
    var obj1 = (IList<Employee>)current[item.ObjType]; it works.