I’ve got the following LINQ query.
// Query the database
IEnumerable<BestSeller> best_sellers = from bs in (db.smd_group)
where bs.COMPANY == "SMD Textiles"
where bs.DOCDATE > six_months_back
where bs.CUSREF == customer.customer_ref
group bs by bs.PRODCODE into g
orderby g.Sum(x => x.MQTY) descending
select new BestSeller()
{
product_code = g.Key.Trim(),
total_quantity = Convert.ToString(g.Sum(x => x.MQTY)),
// ERROR Occurs when the following line is removed
//product_description = g.First().prd_prddes
};
// Get the top 25 products
top25 = best_sellers.Take(25);
As you can see, I have commented out a line where my BestSeller objects are created.
I wish to set the product_description within my BestSellerobject. So I added the line `below:
product_description = g.First().prd_prddes
“prd_prddes” is the name of the column which holds our product description.
However, as soon as I add this line to my query I get a strange error:
Invalid column name ‘PRODCODE’.
Invalid column name ‘PRODCODE’.
Invalid column name ‘PRODCODE’.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.Exception Details: System.Data.SqlClient.SqlException: Invalid column
name ‘PRODCODE’. Invalid column name ‘PRODCODE’. Invalid column name
‘PRODCODE’.
The column name PRODCODE clearly isn’t invalid, because it works just fine if I remove the product_description line.
It’s very peculiar…
It looks like whatever you have in
gdoesn’t have a column named'PRODCODE'Personally, What I would do, is I’d just select
gin your select statement, and then I’d make a break-point and use the debugger see what’s in it.