With help from StackOverflow today, I have gotten my data layer constructed return data from my XML file to my Business Logic Layer. However, I can’t seem to get the data from my business objects layer. The values are all null. Sorry, to be such a newbie…. Thanks in advance.
Business logic layer:
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;
}
Data access layer:
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;
}
This line:
Simply sets
obj1to a new instance ofAccountDetailswhich would be full of empty strings.You probably need to change
getCustDetailsin your DAL to return an instance ofAccountDetailsinstead of anIEnumerableof it, and setobj1to that:In your DAL:
Note that if your DAL can’t find an account with the specified
customerId, it will return anull(which is the default value of a class). You will need to check the return value against null before using if you do not want aNullReferenceExceptionto be thrown in such an eventuality.