代码之家  ›  专栏  ›  技术社区  ›  Oleg Sh

LinqToEntities GroupJoin ArgumentException异常

  •  0
  • Oleg Sh  · 技术社区  · 6 年前

    我有以下型号:

    public class UserPage
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Path { get; set; }
        public bool Editable { get; set; }
    }
    
    public class UserPageSetting
    {
        public int UserId { get; set; }
        public int PageId { get; set; }
        public bool Published { get; set; } = true;
        public DateTime? Modified { get; set; }
    
        public virtual UserPage UserPage { get; set; }
    }
    

    我有以下linq:

            var joined = _dbContext.UserPages.GroupJoin(_dbContext.UserPageSettings, i => i.Id, o => o.PageId, (i, o) => o
               .Select(x => new UserPageSettingDto { Editable = i.Editable, Id = i.Id, Modified = x.Modified, Name = i.Name, Path = i.Path, Published = x.Published })
               .DefaultIfEmpty(new UserPageSettingDto { Id = i.Id, Name = i.Name, Path = i.Path, Published = true, Editable = true }))
               .SelectMany(x => x).ToList();
    

    ArgumentException:类型的表达式 'System.Collections.Generic.IEnumerable'1[TmsApi.Core.UserPageSetting]' 不能用于返回类型 'System.Collections.Generic.IEnumerable'1[TmsApi.Dto.UserPageSettingDto]'

    怎么了?

    0 回复  |  直到 6 年前
    推荐文章