Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot be translated into a LINQ to Entities store expression from within a GroupBy LINQ query
    primarykey
    data
    text
    <p>Casting a value in the extension method and the function in the edmx file is casting a value from a string to what we want.</p> <p>That's fine as long as I would know what the <em>a.Rating.RatingValue</em> and <em>c.RatingId</em> values are ahead of time. They are not hardcoded, nor do I know what the values would be ahead of time.</p> <p>UNfortunately, the first value is a Byte and the second value is an Int32.</p> <p>So, in my extension methods, I have to set them up as follows. Note that <em>Object.Parse(value)</em> only works if the value is a string, so I can't do it like that.</p> <p>With the below code, I'm still getting the same error message and is very frustrating. I don't know what else I need to do in order for it to convert successfully.</p> <p>I have a requirement to get this in by tomorrow. If anyone could be of help, I would appreciate it.</p> <p>Here is my query:</p> <pre><code>var restaurants = await DbContext.Restaurants.GroupBy(g =&gt; g).Select(s =&gt; new RestaurantList() { Name = s.Key.Name, City = s.Key.City, Phone = s.Key.Phone, AvgRating = s.Average(a =&gt; EdmxExtensionMethods.ParseDecimal(a.Rating.RatingValue)), NbrOfPeopleRating = s.Distinct().Count(c =&gt; EdmxExtensionMethods.ParseBoolean(c.RatingId)), Id = s.Key.Id }).ToListAsync(); return restaurants; } </code></pre> <p>Here are my extesnion methods. Again this class is outside the EDMX file on the root of the project:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.Entity; namespace BillYeagerDB { public partial class EdmxExtensionMethods : DbContext { [DbFunctionAttribute("BillYeagerDB", "ParseDecimal")] public static Decimal ParseDecimal(Int16 int16value) { return Convert.ToDecimal(int16value); } [DbFunctionAttribute("BillYeagerDB", "ParseBoolean")] public static bool ParseBoolean(Int32 intvalue) { return Convert.ToBoolean(intvalue); } } } </code></pre> <p>These are my functions inside the EDMX file:</p> <pre><code>&lt;edmx:ConceptualModels&gt; &lt;Schema Namespace="BillYeagerModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm"&gt; &lt;Function Name="ParseDecimal" ReturnType="Edm.Decimal"&gt; &lt;Parameter Name="bytevalue" Type="Edm.Byte" /&gt; &lt;DefiningExpression&gt; cast(bytevalue as Edm.Decimal) &lt;/DefiningExpression&gt; &lt;/Function&gt; &lt;Function Name="ParseBoolean" ReturnType="Edm.Boolean"&gt; &lt;Parameter Name="intvalue" Type="Edm.Int32" /&gt; &lt;DefiningExpression&gt; cast(intvalue as Edm.Boolean) &lt;/DefiningExpression&gt; &lt;/Function&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload