We need to populate a bunch of controls on a form using Linq-to-SQL to retrieve the data. In order to get the data, we need to join several tables.
We have the following method:
First file:
public IEnumerable<object> getPRs()
{
DataContext db = new DataContext();
var prQuery = (from p in db.Invoice
join prd in db.InvoiceDetails on p.ID equals prd.ID
join pra in Accounting on p.ID equals pra.ID
where 1 == 1
orderby p.DownloadDate descending, p.PRNumber, Convert.ToInt32(p.Item)
select new
{
p.ID,
DownloadDate = Convert.ToString(p.DownloadDate),
p.PRNumber,
p.Item,
p.Material,
p.ClientMaterial,
p.Description,
p.Client,
p.Price,
p.UC,
prd.Supplier,
prd.Duns,
prd.RFQ,
prd.RFQDate,
prd.PO,
prd.PODate,
POValue = prd.Price * prd.Quantity,
pra.SO,
pra.SODate,
pra.SOValue,
pra.GR,
pra.GRDate,
pra.GI,
pra.GIDate,
pra.SInvoice,
pra.SInvoiceDate,
pra.CInvoice,
pra.CInvoiceDate,
p.isActive
}).ToList();
return prQuery;
}
And we are calling the method like this on the second file:
IEnumerable<object> data = FirstFile.GetPRs();
PRNumberTextBox.Text = data.PRNumber;
The last line will give an error because we can't access the PRNumber member from the data object. In order to fill in all the text boxes, how can we call our function and add the necessary info?
IEnumerable<object>doesn't havePRNumberproperty.