I have a table called InvestigatorGroupUser
with the following columns:
InvestigatorGroupUserId
, UserId
, and InvestigatorGroupId
I am trying to pull the common InvestigatorGroup that two userid's share but it does not like when I use FirstOrDefault()
. I get the message:
"Cannot implicitly convert type System.Linq.IGrouping to InvestigatorGroupUser".
My code is as follows:
public InvestigatorGroupUser GetCommonGroupId(string userId, string investigatorUserId)
{
using (GameDbContext entityContext = new GameDbContext())
{
string[] ids = new[] { userId, investigatorUserId };
return entityContext.InvestigatorGroupUsers
.Include(i => i.InvestigatorGroup)
.Where(i => i.InvestigatorGroup.IsTrashed == false)
.Where(i => ids.Contains(i.UserId))
.OrderByDescending(i => i.InvestigatorGroupId)
.GroupBy(e => e.InvestigatorGroupId)
.Where(i => i.Count() > 1)
.FirstOrDefault();
}
}
My entity is as follows:
public class InvestigatorGroupUser : IIdentifiableEntity
{
public InvestigatorGroupUser()
{
this.GamesPlayed = new HashSet<GamePlayed>();
this.AssignedGames = new HashSet<AssignedGame>();
}
public int InvestigatorGroupUserId { get; set; }
public string UserId { get; set; }
public int InvestigatorGroupId { get; set; }
public InvestigatorGroup InvestigatorGroup { get; set; }
public virtual ICollection<GamePlayed> GamesPlayed { get; private set; }
public virtual ICollection<AssignedGame> AssignedGames { get; set; }
public int EntityId
{
get { return InvestigatorGroupUserId; }
set { InvestigatorGroupUserId = value; }
}
}
Thanks for all your help!