Reputation: 471
public partial class GoodsCode_EAN
{
public string GoodsCode { get; set; }
public string EAN { get; set; }
}
This is model where GoodsCode is unique every time but EAN not
var test = _context.GoodsCode_EAN
.FromSql($"SELECT * FROM dbo.fnGoodsCode_EAN({SavedData.Entities.id_cenoprov})")
.GroupBy(p => p.EAN, StringComparer.OrdinalIgnoreCase)
.ToDictionary(g => g.Key, g => g.ToList(), StringComparer.OrdinalIgnoreCase);
So I just try to group every elements with same EAN to dictionary and getting this exception...
System.NotSupportedException: 'Could not parse expression value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[ProfiKasa.Portal.Models.newModel.CisloZbozi_EAN]).FromSql("SELECT * FROM dbo.fnCisloZbozi_EAN(1)", __p_0).GroupBy(p => p.EAN, __p_1)': This overload of the method 'System.Linq.Queryable.GroupBy' is currently not supported.'
When I remove ToDictionary
everything work...
Any ideas?
Thanks!
Upvotes: 2
Views: 5748
Reputation: 30052
Entity framework doesn't undestand the StringComparer
enumeration to begin with. Actually, it doesn't support the entire overload of GroupBy
that takes a second parameter (IEqualityComparer<T>
).
You can use ToLower()
as an alternative because it is supported and can be translated into SQL:
.GroupBy(p => p.EAN.ToLower())
Upvotes: 1