I have been using the same model for a while. I recently added a new view to the database that selects 4 columns from my table and groups them. I intend to use this view as a kendo grid master row (easiest way I found for applying grouping on 1M+ records). The columns I use are Fuel, SupplierName, PlanName & Duration
I look at the data on the database, and through visual studios server explorer and all the records are unique. Good - as it should be.
I get the set using the EF models and it's all wrong:
I get the correct number of items
I get the correct number of records for each SupplierName (1 for the first, 13 for the second, etc)
The first record for each SupplierName is correct
All other records under the same SupplierName are duplicates of the first SupplierName record
This is where my head kinda imploded. I'll add the code for each step in the "What have you tried" section.
Theses are the first 5 results I get from the db directly:
PlanName Duration Fuel SupplierName
1 year Fixed 1 year Electricity Dual Energy Direct Limited
Axis 12 1 year Electricity Axis For Business
Axis 12 1 year Gas Axis For Business
Axis 24 2 year Electricity Axis For Business
Axis 24 2 year Gas Axis For Business
But this is what I get back
PlanName Duration Fuel SupplierName
1 year Fixed 1 year Electricity Dual Energy Direct Limited
Axis 12 1 year Electricity Axis For Business
Axis 12 1 year Electricity Axis For Business
Axis 12 1 year Electricity Axis For Business
Axis 12 1 year Electricity Axis For Business
There are many examples where PlanName, Duration and Fuel should all be different, but in my EF results they are all duplicated from the first row. For all I can tell, the SupplierName is also duplicated, but the SupplierName appears to at least have the correct number of result.
NB: When I sort or filter the data, they apply to the query, not the results so the first row for a Supplier will change, but the all subsequent rows are then duplicated from the new first row.
What I have tried:
MySql view:
CREATE
ALGORITHM = UNDEFINED
DEFINER = `xxx`@`%`
SQL SECURITY DEFINER
VIEW `baserateupliftviewheader` AS
SELECT
`br`.`PlanName` AS `PlanName`,
`br`.`Duration` AS `Duration`,
`br`.`SupplierId` AS `SupplierId`,
`br`.`Fuel` AS `Fuel`,
`s`.`SupplierName` AS `SupplierName`
FROM
(`baserates` `br`
JOIN `suppliers` `s` ON ((`br`.`SupplierId` = `s`.`SupplierId`)))
GROUP BY `br`.`PlanName` , `br`.`Duration` , `br`.`SupplierId` , `br`.`Fuel` , `s`.`SupplierName`
The EF SelectAll Query:
public static IQueryable<baserateupliftviewheader> Query(xxxEntities db = null)
{
if (db == null)
db = new xxxEntities();
return db.baserateupliftviewheaders;
}
public static List<baserateupliftviewheader> SelectAll(xxxEntities db = null)
{
if (db == null)
db = new xxxEntities();
return Query(db).ToList();
}