Код: Выделить всё
public class ContactAddress
{
[Key]
public int Id { get; set; }
[ForeignKey(nameof(Contact))]
public int ContactId { get; set; }
public virtual Contact Contact { get; set; }
[ForeignKey(nameof(Continent))]
public int? ContinentId { get; set; }
public virtual Continent Continent { get; set; }
[ForeignKey(nameof(Country))]
public int? CountryId { get; set; }
public virtual Country Country { get; set; }
}
public class GeoStatsModel
{
public int Id { get; set; } // Country Id
public string Name { get; set; } //Country Name
public int Count { get; set; }
}
< /code>
удалось генерировать запрос, как ниже < /p>
List response = new List();
response = context.ContactAddresses
.Where(a => a.IsPrimary == true && contactIds.Contains(a.ContactId))
.GroupBy(a => a.CountryId)
.Select(g => new GeoStatsModel
{
Id = (int)g.Key,
Name = (g.First().Country!=null)? g.First().Country.Name: "",
Count = g.Count()
}).ToList();
< /code>
На момент выполнения я получаю ошибку: < /p>
выражение Linq /> Valuebufferexpression:
projectionbindingexpression: umptyprocemember
isnullable: false < /p>
.select(s => s.country) .first () 'не может быть переведено. Либо
Перепишите запрос в форме, которая может быть переведена, либо перейти на
клиентскую оценку явно, вставив призыв к «Asenumerable»,
'Asasyncemerable', 'tolist' или 'tolistasync'. См.
https://go.microsoft.com/fwlink/?linkid=2101038 для получения дополнительной информации.>
Подробнее здесь: https://stackoverflow.com/questions/709 ... key-column
Мобильная версия