Good evening, I'm two days trying to solve this problem and got nothing. I am suspicious that it is a bug, could someone help me? I am getting the following error message.
Unknown column 'Distinct1.nCdSite' in 'where clause'
[MySqlException (0x80004005): Unknown column 'Distinct1.nCdSite' in 'where clause'] MySql.Data.MySqlClient.MySqlStream.ReadPacket() +501 MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) +450 MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +136 MySql.Data.MySqlClient.MySqlDataReader.NextResult() +1269 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +2528 MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +22 . . .
I have the following code:
Model:
[Table("pagina")]
public class pagina
{
[Key]
public long nCdPagina { get; set; }
public long nCdVisitante { get; set; }
public string sDsUrlReferencia { get; set; }
public string sDsPalavraChave { get; set; }
public string sDsTitulo { get; set; }
[ForeignKey("nCdVisitante")]
public visitante visitante { get; set; }
}
public class retorno
{
public long Key { get; set; }
public int Online { get; set; }
}
[Table("site")]
public class site
{
[Key]
public long nCdSite { get; set; }
public string sDsTitulo { get; set; }
public string sDsUrl { get; set; }
public DateTime tDtCadastro { get; set; }
}
[Table("visitante")]
public class visitante
{
[Key]
public long nCdVisitante { get; set; }
public long nCdSite { get; set; }
public string sDsIp { get; set; }
public DateTime tDtCadastro { get; set; }
public DateTime tDtAtualizacao { get; set; }
[ForeignKey("nCdSite")]
public site site { get; set; }
}
Query:
return (from pag in this.context.pagina.Include("visitante").Include("site")
group pag by pag.visitante.nCdSite into g
select new retorno
{
Key = g.Key,
Online = g.Select(e => e.visitante.sDsIp).Distinct().Count()
}).ToList<retorno>();
The problem only occurs when I place Distinct()
. Count()
if let alone works perfectly.