晚上好,我两天试图解决这个问题,但一无所获。我怀疑这是一个错误,有人可以帮助我吗?我收到以下错误消息。
“where 子句”中的未知列“Distinct1.nCdSite”
[MySqlException (0x80004005): 'where 子句'中的未知列 'Distinct1.nCdSite'] 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 行为) +2528 MySql.Data。 Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior 行为)+22。. .
我有以下代码:
模型:
[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; }
}
询问:
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>();
问题仅发生在我放置Distinct()
. Count()
如果更不用说完美地工作了。