entityframework从sql server迁移到mysql后执行查询时出现问题

9jyewag0  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(410)

ey,最近我将一个数据库从sql server迁移到了mysql,安装了mysql.data 6.10.6和mysql.data.entity 6.9.11,从mysql更新了ado模型以重新生成所有的*.cs,大部分代码运行正常,但是我在尝试执行此查询时遇到了一个错误:

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
nlejzf6q

nlejzf6q1#

当您更改数据库时,忘记了重建每一列,这就是错误所说的,请处理它

0ve6wy6x

0ve6wy6x2#

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

相关问题