Seems like this is a recorring problem for me. I am again having a problem with casting type when I use an anonymous collection. My query from the XML file returns a collection of string values. I am trying to return these values from my data access layer to my business logic layer. Thanks in advance.
public string[] getCustDetails(string customerId)
{
//Pulls customer information for selected customer
var doc = XDocument.Load("Portfolio.xml");
var custRecord = from account in doc.Descendants("acct")
let acct = account.Element("acct")
where (string)account.Attribute("custid").Value == customerId
select new
{
Fname = (string)account.Attribute("fname").Value,
Lname = (string)account.Attribute("lname").Value,
Ssn = (string)account.Attribute("ssn").Value,
Dob = (string)account.Attribute("dob").Value,
Custid = (string)account.Attribute("custid").Value
};
return ?????
}
You can’t use anonymous types are either parameters to a method or a return type.
I suggest creating a simple class with the properties you need and use that instead of an anonymous type.