我一直在使用相同的模型。我最近为数据库添加了一个新视图,从我的表中选择4列并对它们进行分组。我打算将此视图用作kendo网格主行(我发现在1M +记录上应用分组的最简单方法)。我使用的列是Fuel,SupplierName,PlanName和Duration。
我查看数据库上的数据,并通过visual studios服务器资源管理器和所有记录都是唯一的。好 - 应该是。
我使用EF模型得到了这个集合并且一切都错了:
这是我的头脑有点崩溃的地方。我将在最后添加代码。
这些是我直接从db获得的前5个结果:
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
但这就是我回来的原因
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
有很多例子,PlanName,Duration和Fuel都应该有所不同,但在我的EF结果中,它们都是从第一行复制的。据我所知,SupplierName也是重复的,但SupplierName似乎至少有正确的结果数。
注意:当我对数据进行排序或过滤时,它们会应用于查询,而不是结果,因此供应商的第一行将更改,但随后的所有行都将从新的第一行复制。
MySql视图:
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`
EF SelectAll查询:
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();
}