mysql Entity Framework with Distinct

非 Y 不嫁゛ 提交于 2019-12-08 07:39:10

问题


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.

来源:https://stackoverflow.com/questions/15117391/mysql-entity-framework-with-distinct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!