I have two tables, Customers and Orders. 1 customer can have multiple orders. There is a link between the two tables.
Currently using Linq to SQL to get the data and display it. The database has grown and results were displaying pretty slow.
After some reading I added a Stored Procedure (Added the SP to the dbml file which returns ISingleResult so created a new method where i iterated through the SP data and added it to my Customers object list). I did this to speed up in obtaining and displaying the data. So far this worked well.
The problem is when I used to get order details by a customer, I used to write this
foreach (Customer c in Customer)
{
foreach (Order o in c.Orders)
{
// other logic here
}
}
Using the Stored Procedure method c.Orders was null so I added the relevant relation to the SP but Orders is always null - the only thing that has changed is the number of rows returned which is the same as the number of orders the customer has placed, however I cant iterate through the orders like I did prior to adding the SP?
Any thoughts on where ive gone wrong or what to do?
My Stored Procedure:
Select Customers.*, Orders.ID
FROM
Customers INNER JOIN Orders ON Customers.Ordersid = Orders.Ordersid
In code I have
public List<Customer> GetCustomers
{
ISingleResult<StoredProcedureName> AllCustomers = myDC.StoreProcedureName;
List<Customer> Customers = new List<Customer>();
foreach (var c in AllCustomers)
{
//Add each property from SP into List properties and return List
}
//....
}