Note that there are some explanatory texts on larger screens.

plurals
  1. POInner Join on three tables using Linq
    text
    copied!<p>How to do inner join on three tables, when one of the tables is using group by. I am able to write this query but it returns error on run time. So how should I modify my query.</p> <pre><code>var pastDate = DateTime.Now.Date.AddDays(-1); var query = from l in db.picturelikes 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 join u in db.users on pgroup.FirstOrDefault().iduser equals u.iduser select new SortedDto { IdPictures = pgroup.FirstOrDefault().idpictures, IdUser = pgroup.FirstOrDefault().iduser, totalrating = pgroup.Average(l =&gt; (float?)l.likenumber) ?? 0, // pl.Where(a =&gt; a.likenumber!= null).Average(c =&gt; c.likenumber) sex =u.sex, username =u.username, dob = u.dob }; return query; </code></pre> <p>This is the exception i get with my present code, </p> <blockquote> <p>InnerException: { Message: "An error has occurred.", ExceptionMessage: "Unknown column 'Project2.idpictures' in 'where clause'", ExceptionType: "MySql.Data.MySqlClient.MySqlException", StackTrace: " at MySql.Data.MySqlClient.MySqlStream.ReadPacket() 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.ExecuteDbDatoiaReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)" }</p> </blockquote> <p>Is my query legit? Is it the way to do three inner joins when using groupby.</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