Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
实体框架Linq查询返回不正确的MySQL数据库值_Mysql_Linq_Entity Framework - Fatal编程技术网

实体框架Linq查询返回不正确的MySQL数据库值

实体框架Linq查询返回不正确的MySQL数据库值,mysql,linq,entity-framework,Mysql,Linq,Entity Framework,我有一个问题: var cams = (from c in db.cameras join s in db.camera_sites on c.camera_site_id equals s.id join o in db.servers on s.server_id equals o.id where (c.enabled == "yes"

我有一个问题:

    var cams = (from c in db.cameras
                        join s in db.camera_sites on c.camera_site_id equals s.id
                        join o in db.servers on s.server_id equals o.id
                        where (c.enabled == "yes"
                        && s.enabled == "yes"
                        && o.enabled == "yes" 
                        && o.type == "hosted"
                        && o.server_method == "webservices"
                        && c.account_id == accountId)
                        select new EventCamera_Named { Camera = c, SiteName = s.name, ServerName = o.name }).ToList();
问题是所选的SiteName与Camera.name相同

生成的sql是:

    SELECT
    `Filter1`.`id`, 
    `Filter1`.`account_id`, 
    `Filter1`.`camera_site_id`, 
    `Filter1`.`enabled`, 
    `Filter1`.`name`, 
    ...,
    `Filter1`.`name` AS `name1`, 
    `Extent3`.`name` AS `name2`

    FROM (SELECT
    `Extent1`.`id`, 
    `Extent1`.`account_id`, 
    `Extent1`.`camera_site_id`, 
    `Extent1`.`enabled`, 
    `Extent1`.`name`, 
    ..., 
    `Extent2`.`id` AS `id1`, 
    `Extent2`.`account_id` AS `account_id1`, 
    `Extent2`.`server_id`, 
    ...
    FROM `cameras` AS `Extent1` INNER JOIN `camera_sites` AS `Extent2` ON `Extent1`.`camera_site_id` = `Extent2`.`id`
    WHERE ('yes' = `Extent1`.`enabled`) AND ('yes' = `Extent2`.`enabled`)) AS `Filter1` INNER JOIN `servers` AS `Extent3` ON `Filter1`.`server_id` = `Extent3`.`id`
    WHERE ((('yes' = `Extent3`.`enabled`) AND ('hosted' = `Extent3`.`type`)) AND ('webservices' = `Extent3`.`server_method`)) AND (`Filter1`.`account_id` = 39884476)
如何重写查询以返回正确的值,以及是什么导致它变得混乱?

当我在数据库引用它生成的sql正确后直接移动启用的检查时

    var cams = (from c in db.cameras 
                    where c.enabled == "yes"
                    join s in db.camera_sites on c.camera_site_id equals s.id 
                    where s.enabled == "yes"
                    join o in db.servers on s.server_id equals o.id
                    where (o.enabled == "yes" 
                    && o.type == "hosted"
                    && o.server_method == "webservices"
                    && c.account_id == accountId)
                    select new EventCamera_Named { Camera = c, SiteName = s.name, ServerName = o.name }).ToList();
它是否在内部select子句中选择Extent2.name?