Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting exception when using linq
    text
    copied!<p>It's not duplicate of this question(<a href="https://stackoverflow.com/questions/19053489/how-to-do-multiple-joins-when-using-groupby-in-linq">How to do multiple joins when using groupby in linq</a>), situation has changed. </p> <p>I have a picture rating table in my database. For every new rating, a new picture rating table row will be created. I am grouping those ratings by lastweek and pictureid, meaning all the ratings for one single pic in the last week will be accumulated and become one rating.Then i will be able to sort them by their count. Then I am joining two other tables two show user and picture related details. </p> <p>This is my code :</p> <pre><code>public IQueryable&lt;SortedDto&gt; GetOne() { var pastDate = DateTime.Now.Date.AddDays(-1); var combo = from l in db.picturerating where l.iddatetime &gt; pastDate group l by l.idpictures into pgroup let count = pgroup.Count() orderby count descending join p in db.picturedetails on pgroup.FirstOrDefault().idpictures equals p.idpictures into first join u in db.users on pgroup.FirstOrDefault().iduser equals u.iduser into second select new SortedDto { IdPictures = pgroup.FirstOrDefault().idpictures, IdUser = pgroup.FirstOrDefault().iduser, IdDatetime = first.FirstOrDefault().pictime, totalrating = pgroup.Average(l =&gt; (float?)l.rating) ?? 0, sex =second.FirstOrDefault().sex, username =second.FirstOrDefault().username, dob = second.FirstOrDefault().dob }; return combo; } </code></pre> <p>When running this code I get an exception like this :</p> <blockquote> <p>InnerException: {<br> Message: "An error has occurred.",<br> ExceptionMessage: "Unknown column 'Apply1.idpictures' in 'where clause'",<br> ExceptionType: "MySql.Data.MySqlClient.MySqlException" </p> <p>StackTrace:</p> <p>at MySql.Data.MySqlClient.MySqlStream.ReadPacket()<br> at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&amp; affectedRow, Int64&amp; insertedId) at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32&amp; affectedRows, Int64&amp; insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)</p> </blockquote> <p>So why am I getting this exception? Any thing wrong with my linq query?</p>
 

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