使用LINQ TO SQL 中的左外连接中DEFAULTIFEMPTY为什么赋不上默认值

进行SQL SERVER左外连接想用DEFAULTIFEMPTY()试着赋予默认值,结果赋不上是什么原因呢?

代码片段

控制台输出

            Location defaultLoc = new Location { Id = String.Empty, Name = "黑凤梨", Postcode = String.Empty };
            var re = from u in _context.UserMsg
                     join l in _context.Location
                     on u.LocationId equals l.Id
                     into LocGroup
                     from item in LocGroup.DefaultIfEmpty(defaultLoc)
                     where u.Status == "0"
                     select new
                     {
                         PerId = u.Id,
                         PerName = u.Name,
                         PerAge = u.Age,
                         PerLocation = item.Name
                     };
            var rre = from u in _context.UserMsg
                      join l in _context.Location
                      on u.LocationId equals l.Id
                      into LocGroup
                      select new { UserName = u.Name,Loc = LocGroup };
            List<Location> gg = new List<Location>();
            LogHelper.Logger.Info(JsonConvert.SerializeObject(gg));
            LogHelper.Logger.Info(JsonConvert.SerializeObject(gg.DefaultIfEmpty(defaultLoc)));
            LogHelper.Logger.Info(JsonConvert.SerializeObject(rre));
            LogHelper.Logger.Info(JsonConvert.SerializeObject(re));
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问