1
I am doubtful to conduct a consultation.
I need to list in this query only the offers that are within the age group listed in view in the fields IDADEMINIMA and IDADEMAXIMA passing only the parameter of dtnascimento. Can help?
public IQueryable<VW_PARCEIROSOFERTAS> ConsultaOfertas(string pEmpresa, string pOferta, string dtnascimento)
{
var query = this.dbSet.AsNoTracking().Where(p => p.EMPRESA == pEmpresa && p.CODOFERTA == pOferta);
if (!String.IsNullOrEmpty(dtnascimento) || !String.IsNullOrWhiteSpace(dtnascimento))
{
query = query.Where(c => Convert.ToDateTime(dtnascimento) <= DateTime.Now.AddYears(Convert.ToInt32(c.IDADEMINIMA))
&& Convert.ToDateTime(dtnascimento) >= DateTime.Now.AddYears(Convert.ToInt32(c.IDADEMAXIMA)));
}
return query;
}
View VW_PARCEIROSOFERTAS:
public partial class VW_PARCEIROSOFERTAS
{
[Key]
[Column(Order = 0)]
[StringLength(2)]
public string EMPRESA { get; set; }
[Key]
[Column(Order = 1)]
[StringLength(6)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string CODPARCEIRO { get; set; }
[StringLength(30)]
public string NOMEPARCEIRO { get; set; }
[StringLength(30)]
public string RAZAOSOCIAL { get; set; }
[StringLength(18)]
public string CNPJ { get; set; }
[StringLength(6)]
public string PRODUTO { get; set; }
public string CODOFERTA { get; set; }
[StringLength(30)]
public string NOMEOFERTA { get; set; }
[Column(TypeName = "varchar")]
public string FLAGWEBAUTOMATICO { get; set; }
[Column(TypeName = "varchar")]
public string TIPOFAIXAPRECO { get; set; }
[Column(TypeName = "numeric")]
public decimal? PRAZOINICIAL { get; set; }
[Column(TypeName = "numeric")]
public decimal? PRAZOFINAL { get; set; }
[Column(TypeName = "numeric")]
public decimal? VALORINICIAL { get; set; }
[Column(TypeName = "numeric")]
public decimal? VALORFINAL { get; set; }
[Column(TypeName = "numeric")]
public decimal? VALORPRODUTO { get; set; }
[Column(TypeName = "numeric")]
public decimal? COMISSAO { get; set; }
[Column(TypeName = "numeric")]
public decimal? IDADEMINIMA { get; set; }
[Column(TypeName = "numeric")]
public decimal? IDADEMAXIMA { get; set; }
public DateTime? VIGENCIAINICIAL { get; set; }
public DateTime? VIGENCIAFINAL { get; set; }
}
It will give error because it is trying to use Convert.Todatetime() in a Queryable. Same for Convert.Toint32(). Enter the VW_PARCEIROSOFERTAS code and if possible the error that is giving.
– George Wurthmann
Hello Gerge, all right? I am including the code, the error that occurs is the one you mentioned. (datetime conversion error and int32).
– tssantana