Skip to content

The given key 'EmptyProjectionMember' was not present in the dictionary #20277

Closed

Description

In the following method, i got exception which i mentioned the title. But if i uncomment the following line it works.

// PreferenceIds = new List()

In which cases this type of exception may occur, any clue?

       public static Expression<Func<ReservationGuest, GuestDto>> GuestSelector
        {
            get
            {
                return g => new GuestDto
                {
                    Id = g.Id,
                    ProfileId = g.ProfileId,
                    VipLevelId = g.ProfileId.HasValue ? g.Profile.VipLevelId : g.ProfileId,
                    VipLevelCode = g.ProfileId.HasValue
                        ? g.Profile.VipLevel.Code
                        : (g.VipLevelId.HasValue ? g.VipLevel.Code : null),
                    LanguageId = g.ProfileId.HasValue ? g.Profile.Language.Id : g.LanguageId,
                    LanguageName = g.ProfileId.HasValue
                        ? g.Profile.Language.Name
                        : (g.Language != null ? g.Language.Name : string.Empty),
                    BirthDate = g.ProfileId.HasValue ? g.Profile.BirthDate : null,
                    IsOwner = g.IsOwner,


                    // PreferenceIds = new List<Guid>(),   // works fine
                    PreferenceIds = g.ProfileId != null && g.Profile != null  // exception
                        ? g.Profile.Preferences.Select(p => p.PreferenceId).ToList()
                        : g.Preferences.Select(p => p.PreferenceId).ToList(),


                    FirstName = g.ProfileId.HasValue ? g.Profile.FirstName : g.FirstName,
                    LastName = g.ProfileId.HasValue ? g.Profile.LastName : g.LastName,
                    MiddleName = g.ProfileId.HasValue ? g.Profile.MiddleName : g.MiddleName,
                    PhoneCode = g.ProfileId.HasValue
                        ? g.Profile.Communications
                            .Where(c => c.Type == CommunicationType.Phone && c.IsPreferred)
                            .Select(y => y.PhoneCode).FirstOrDefault()
                        : g.PhoneCode,
                    PhoneNumber = g.ProfileId.HasValue
                        ? g.Profile.Communications
                            .Where(c => c.Type == CommunicationType.Phone && c.IsPreferred)
                            .Select(c => c.Value).FirstOrDefault()
                        : g.PhoneNumber,
                    Email = g.ProfileId.HasValue
                        ? g.Profile.Communications
                            .Where(c => c.Type == CommunicationType.Email && c.IsPreferred)
                            .Select(c => c.Value).FirstOrDefault()
                        : g.Email
                };
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

area-queryclosed-fixedThe issue has been fixed and is/will be included in the release indicated by the issue milestone.customer-reportedtype-bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions