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
C# &引用;如果子查询没有引入EXISTS,则只能在选择列表中指定一个表达式;_C#_Linq_Linq To Sql - Fatal编程技术网

C# &引用;如果子查询没有引入EXISTS,则只能在选择列表中指定一个表达式;

C# &引用;如果子查询没有引入EXISTS,则只能在选择列表中指定一个表达式;,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,我有一个相当复杂的Linq查询: var q = from eiods in LinqUtils.GetTable<EIOfficialDesignee>() let eiodent = eiods.Entity join tel in LinqUtils.GetTable<EntityTelephone>() on new { EntityID = eiodent.ID, TelephoneType = EntityTel

我有一个相当复杂的Linq查询:

var q = from eiods in LinqUtils.GetTable<EIOfficialDesignee>()
        let eiodent = eiods.Entity
        join tel in LinqUtils.GetTable<EntityTelephone>()
        on new { EntityID = eiodent.ID, TelephoneType = EntityTelephone.TTelephone.Office } equals new { tel.EntityID, tel.TelephoneType }
        into Tel
        let Tel1 = Tel.FirstOrDefault()
        join fax in LinqUtils.GetTable<EntityTelephone>()
        on new { EntityID = eiodent.ID, TelephoneType = EntityTelephone.TTelephone.Fax } equals new { fax.EntityID, fax.TelephoneType }
        into Fax
        let Fax1 = Fax.FirstOrDefault()
        join cell in LinqUtils.GetTable<EntityTelephone>().DefaultIfEmpty()
        on new { EntityID = eiodent.ID, TelephoneType = EntityTelephone.TTelephone.Mobile } equals new { cell.EntityID, cell.TelephoneType }
        into Mobile
        let Mobile1 = Mobile.FirstOrDefault()
        where eiods.ID == CurrentEIPatient.EIOfficialDesigneeID
        select new {
          ID = eiods.ID,
          EIODName = eiodent.FormattedName,
          Phone = Tel1 != null ? Tel1.FormattedNumber : "",
          Fax = Fax1 != null ? Fax1.FormattedNumber : "",
          Cellphone = Mobile1 != null ? Mobile1.FormattedNumber : "",
        };
是的,一式三份。这是一个明显的迹象,表明查询问题重复了3次,即在3种不同类型的电话号码中

根据SQL server文档,这来自一个格式错误的查询。但这是林克,看在上帝的份上!这怎么可能是查询的错误呢

除了主要的答案,我也很感谢你对优化我的查询的任何意见


谢谢

我自己解决了,这是为了其他人的利益

魔鬼就在最后的select子句中,特别是:

Phone = Tel1 != null ? Tel1.FormattedNumber : "",
Fax = Fax1 != null ? Fax1.FormattedNumber : "",
Cellphone = Mobile1 != null ? Mobile1.FormattedNumber : "",
FormattedNumber属性是基于
EntityTelephone
对象的
Number
Extension
属性计算的字段。当我用
Number
替换
FormattedNumber
时,一切正常

找到了这个问题的最佳解决方案

Phone = Tel1 != null ? Tel1.FormattedNumber : "",
Fax = Fax1 != null ? Fax1.FormattedNumber : "",
Cellphone = Mobile1 != null ? Mobile1.FormattedNumber : "",