从Sql Server迁移到MySQL后执行查询的EntityFramework问题

时间:2018-04-17 10:52:32

标签: c# mysql .net entity-framework entity-framework-6

Ey,最近我已经将数据库从SQL Server迁移到MySQL,安装了MySql.Data 6.10.6和MySql.Data.Entity 6.9.11,从Mysql更新了ADO模型以重新生成所有* .cs&#39 ; s和大多数代码运行正常,但我尝试执行此查询时出错:

List<int> ids = this.db.functions
              .Where(f => f.active == true
                     && f.actions
                       .Where(af => af.types.name == 'TYPE1'
                              && af.groups
                                 .Where(g => g.users
                                    .Where(u => u.uname == 'user1')
                                    .Count() > 0
                        )
                        .Count() > 0
               )
               .Count() > 0

        )
        .Select(f => f.mod.id)
        .Distinct()
        .ToList();

我收到此错误:

Error de servidor en la aplicación '/'.
Unknown column 'Extent1.id' in 'where clause'
Descripción: Excepción no controlada al ejecutar la solicitud Web actual. 
Revise el seguimiento de la pila para obtener más información acerca del 
error y dónde se originó en el código. 

Detalles de la excepción: MySql.Data.MySqlClient.MySqlException: Unknown 
column 'Extent1.id' in 'where clause'

这是来自EF构建查询的日志,我认为这里出现了问题,EF没有构建查询:(

Opened connection at 17/04/2018 12:40:02 +02:00
SELECT
`Distinct1`.`m_xref`
FROM (SELECT DISTINCT 
`Project5`.`m_xref`
FROM (SELECT
`Extent1`.`m_xref`, 
`Extent1`.`active_b`, 
(SELECT
COUNT(1) AS `A1`
FROM (SELECT
`Project1`.`name`, 
(SELECT
COUNT(1) AS `A1`
FROM (SELECT
(SELECT
COUNT(1) AS `A1`
FROM `user_group_user` AS `Extent5` INNER JOIN `user` AS `Extent6` ON 
`Extent6`.`id` = `Extent5`.`user_xref`
WHERE (`Project2`.`group_xref` = `Extent5`.`group_xref`) AND     
(`Extent6`.`uname`     = @p__linq__0)) AS `C1`
FROM (SELECT
`Extent4`.`group_xref`
FROM `p_group_fun` AS `Extent4`
 WHERE (`Project1`.`fun_xref` = `Extent4`.`fun_xref`) AND     
(`Project1`.`action_xref` = `Extent4`.`action_xref`)) AS `Project2`) AS     
`Project3`
 WHERE `Project3`.`C1` > 0) AS `C1`
FROM (SELECT
`Extent2`.`fun_xref`, 
`Extent2`.`action_xref`, 
`Extent3`.`name`
FROM `actions_fun` AS `Extent2` INNER JOIN `types` AS `Extent3` ON     
`Extent2`.`action_xref` = `Extent3`.`id`
 WHERE `Extent1`.`id` = `Extent2`.`fun_xref`) AS `Project1`) AS `Project4`
 WHERE (@gp1 = `Project4`.`name`) AND (`Project4`.`C1` > 0)) AS `C1`
FROM `functions` AS `Extent1`) AS `Project5`
 WHERE (1 = `Project5`.`active_b`) AND (`Project5`.`C1` > 0)) AS `Distinct1`
-- p__linq__0: 'user1' (Type = String, Size = 7)
-- @gp1: 'TYPE1' (Type = String, IsNullable = false, Size = 7)
-- Executing at 17/04/2018 12:40:03 +02:00
-- Failed in 3 ms with error: Unknown column 'Extent1.id' in 'where clause'

Closed connection at 17/04/2018 12:40:03 +02:00

2 个答案:

答案 0 :(得分:1)

我猜你的数据库表没有像在模型中那样更新,你需要相应地更新数据库,因为MySql没有找到你在查询中使用的Id。

答案 1 :(得分:0)

当您更改数据库时,您忘记重建每一列,错误是什么,请注意它