1
今天在StackOverflow的幫助下,我從我的XML文件中獲取了數據層構造的返回數據到我的業務邏輯層。但是,我似乎無法從我的業務對象層獲取數據。這些值全爲空。對不起,成爲這樣的新手....提前致謝。IEnumerable集合類型,獲取空值
業務邏輯層:
public void getCustDetails(string customerId)
{
DLGetCustomers obj = new DLGetCustomers();
obj.getCustDetails(customerId);
AccountDetails obj1 = new AccountDetails();
FirstName = obj1.Fname;
LastName = obj1.Lname;
SSN = obj1.Ssn;
Dob = Convert.ToDateTime(obj1.Dob);
CustomerId = Convert.ToInt32(obj1.Custid);
TimeSpan ts = DateTime.Now - Convert.ToDateTime(Dob);
Age = ts.Days/365;
}
數據訪問層:
public class AccountDetails
{
public string Fname { get; set; }
public string Lname { get; set; }
public string Ssn { get; set; }
public string Dob { get; set; }
public string Custid { get; set; }
}
public IEnumerable<AccountDetails> getCustDetails(string customerId)
{
//Pulls customer information for selected customer
var doc = XDocument.Load("Portfolio.xml");
var custRecords = from account in doc.Descendants("acct")
let acct = account.Element("acct")
where (string)account.Attribute("custid").Value == customerId
select new AccountDetails
{
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 custRecords;
}
什麼值爲空?你的XML文件是怎樣的? –