Model properties set incorrectly from query
Posted: Fri 13 Mar 2020 02:40
I'm just about tearing my hair out now.
Yet another issue and I'm not sure what is going on here.
We have a model which has similarly named properties Pax1, Pax2, Gross1, Gross2 etc.
I am trying to work around another issue I have posed in another thread, so have these two test queries (what's in the tables etc. doesn't really matter)
When I run the code and look at the values in query2, Pax2, Gross2 and Net2 are all null, yet Pax1, Gross1 and Net1 ARE all set and they have the values that Pax2,Gross2 and Net2 should have. I thought I was going mad and checked and double checked. Those values are not set in this query, they are set in the previous query.
If I copy and paste the exact code into the previous version of the project running LinqToSQL, lo and behold, the values in each of the queries are set as expected.
I was wanting to combine those two queries into one. What I found was if I made the first two queries anonymous types instead of AnalyserModel.DataRow and combined them in the third query into AnalyserModel.DataRow, then it picked up the correct values.
What on earth is going on here ?
This is seriously denting any confidence I have in using this product when something like this can happen.
Yet another issue and I'm not sure what is going on here.
We have a model which has similarly named properties Pax1, Pax2, Gross1, Gross2 etc.
I am trying to work around another issue I have posed in another thread, so have these two test queries (what's in the tables etc. doesn't really matter)
Code: Select all
var query1 = (from data in analysisData
join prod in products on data.Fk_Product equals prod.PrimaryKey
join acc in accounts on data.Fk_Account_Agent equals acc.Fk_Contact
join cont in contacts on acc.Fk_Contact equals cont.PrimaryKey
where data.ProductDate >= dates.StartDate1 && data.ProductDate <= dates.EndDate1
group data by 1 into grp
select new AnalyserModel.DataRow()
{
RowCaption = "All data",
Pax1 = grp.Sum(q => q.Pax),
Gross1 = grp.Sum(q => q.Gross),
Net1 = grp.Sum(q => q.Net),
}).ToList();
var query2 = (from data in analysisData
join prod in products on data.Fk_Product equals prod.PrimaryKey
join acc in accounts on data.Fk_Account_Agent equals acc.Fk_Contact
join cont in contacts on acc.Fk_Contact equals cont.PrimaryKey
where data.ProductDate >= dates.StartDate2 && data.ProductDate <= dates.EndDate2
group data by 1 into grp
select new AnalyserModel.DataRow()
{
RowCaption = "All data",
Pax2 = grp.Sum(q => q.Pax),
Gross2 = grp.Sum(q => q.Gross),
Net2 = grp.Sum(q => q.Net),
}).ToList();
If I copy and paste the exact code into the previous version of the project running LinqToSQL, lo and behold, the values in each of the queries are set as expected.
I was wanting to combine those two queries into one. What I found was if I made the first two queries anonymous types instead of AnalyserModel.DataRow and combined them in the third query into AnalyserModel.DataRow, then it picked up the correct values.
What on earth is going on here ?
This is seriously denting any confidence I have in using this product when something like this can happen.