I have a query method that works, it brings the information from the database, however I am trying to use substring to get a part of a certain value from a table, I am using Iqueryable, but informs that it can not convert string to int, could anyone instruct me to fix the problem, I'm using nhibernate. Follow the code below:
This is my select:
- select fo.year_exercise_ctx, fo.cod_font_group, fo.cod_fonte, fo.name_fonte,
- ne.idt_document, ne.year_document, ne.cod_ug, ne.cod_document, substr (ne.cod_ranking, 54,4)
- from lag4_es_2019.spa_fonte fo
- left join lag4_es_2019.spe_ne ne
- on fo.cod_group_fonte = substr (ne.cod_ranking, 54,1) and fo.cod_fonte = substr (ne.cod_ranking, 56,2)
- where fo.cod_font_font not in (0) and fo.cod_font not in (00)
- order by fo.cod_group_fonte, fo_cod_fonte, ne.cod_ug, ne.cod_document;
My code:
- public static IQueryable
ListAll - {
- ISessionFactory session = FluentHelper.GetSessionFactory (EnumDatabase.MsSqlSiplag);
- IQueryable
- .CreateCriteria
("ne") - .List
(). AsQueryable () - .Select ((i, x) => new {x, str = i.CodSubscription.Substring ("54,4", x)});
- var aa = criterion; //Criterio.List
(). ToList (); - return null;
- }
I tried to implement the condition without success.
- public static IQueryable
ListAll() - {
- ISessionFactory session = FluentHelper.GetSessionFactory(EnumDatabase.MsSqlLag);
- IQueryable
criteria = session.OpenSession() - .CreateCriteria
("ne") - .List
().AsQueryable() - .Where(g => g.Codranking.Contains(g.Codranking.Substring(54, 4), g.Codranking.Substring(54, 1), g.Codranking.Substring(56, 2)));
- //.Select((i, x)=> new {x, str = i.CodClassificacao.Substring("54,4", x) });
- var aa = criteria; //criterio.List
().ToList(); - return null;
- }
- using Domain.Lag.Domain;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Domain.Lag.DataAccess.DTO
- {
- public class EmpenhoDTO
- {
- //public string CodEmpenho { get; set; }
- public virtual string CodClientCTX { get; set; }
- public virtual string IdtDocument { get; set; }
- public virtual string YearExerciseCTX { get; set; }
- public virtual string CodRanking { get; set; }
- public virtual string CodDocument { get; set; }
- public virtual string CodUg { get; set; }
- public virtual string YearDocument { get; set; }
- public override bool Equals(object obj)
- {
- //return AnoExercicio.ToString() == CodCliente.ToString() == CodGrupoFonte.ToString() == CodFonte.ToString();
- if (!(obj is EmpenhoDTO)) return false;
- var objA = obj as EmpenhoDTO;
- return (this.YearExerciseCTX == objA.YearExerciseCTX && this.CodClientCTX == objA.CodClientCTX && this.IdtDocument == objA.IdtDocument &&
- this.CodDocument ==objA.CodDocument && this.CodUg==objA.CodUg && this.YearDocument ==objA.YearDocument );
- }
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
- }
- }
Robson AmaralPosted Feb 14, 2019, 2:34 PM
Vivek KumarPosted Feb 13, 2019, 12:17 PM
Salman BegPosted Feb 13, 2019, 9:04 AM