1

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.

Slauma
  • 175,098
  • 59
  • 401
  • 420
famadori
  • 83
  • 2
  • 9
  • See [this post](http://stackoverflow.com/questions/15083627/linq-mysql-group-by-year-month-day-select-year-month-day-count). Seems that the query provider has a hard time creating correct sub queries. Did you check the generated SQL? – Gert Arnold Feb 27 '13 at 18:20
  • I contacted mysql and it really is a bug and have reported it as such. http://bugs.mysql.com/bug.php?id=68513 – famadori Feb 28 '13 at 11:34

0 Answers0