Robson Amaral

Robson Amaral

  • NA
  • 132
  • 15.7k

Problem with using substring

Feb 12 2019 8:43 AM
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:
  1. select fo.year_exercise_ctx, fo.cod_font_group, fo.cod_fonte, fo.name_fonte,  
  2.        ne.idt_document, ne.year_document, ne.cod_ug, ne.cod_document, substr (ne.cod_ranking, 54,4)  
  3.   from lag4_es_2019.spa_fonte fo  
  4.   left join lag4_es_2019.spe_ne ne  
  5.      on fo.cod_group_fonte = substr (ne.cod_ranking, 54,1) and fo.cod_fonte = substr (ne.cod_ranking, 56,2)  
  6.   where fo.cod_font_font not in (0) and fo.cod_font not in (00)  
  7.      order by fo.cod_group_fonte, fo_cod_fonte, ne.cod_ug, ne.cod_document;  
 My code:
  1. public static IQueryable ListAll  
  2.         {  
  3.             ISessionFactory session = FluentHelper.GetSessionFactory (EnumDatabase.MsSqlSiplag);  
  4.             IQueryable 
  5.                 .CreateCriteria  ("ne")  
  6.                 .List  (). AsQueryable ()  
  7.                 .Select ((i, x) => new {x, str = i.CodSubscription.Substring ("54,4", x)});  
  8.   
  9.               
  10.   
  11.             var aa = criterion; //Criterio.List (). ToList ();  
  12.             return null;  
  13.         }  
I tried to implement the condition without success.
  1. public static IQueryable ListAll()  
  2.         {  
  3.             ISessionFactory session = FluentHelper.GetSessionFactory(EnumDatabase.MsSqlLag);  
  4.             IQueryable criteria = session.OpenSession()  
  5.                 .CreateCriteria("ne")  
  6.   
  7.                 .List().AsQueryable()  
  8.                 .Where(g => g.Codranking.Contains(g.Codranking.Substring(54, 4), g.Codranking.Substring(54, 1), g.Codranking.Substring(56, 2)));  
  9.                 //.Select((i, x)=> new {x, str = i.CodClassificacao.Substring("54,4", x) });  
  10.   
  11.             var aa = criteria; //criterio.List().ToList();  
  12.             return null;  
  13.         }  
 
  1. using Domain.Lag.Domain;  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.Linq;  
  5. using System.Text;  
  6.   
  7. namespace Domain.Lag.DataAccess.DTO  
  8. {  
  9.     public class EmpenhoDTO  
  10.     {  
  11.         //public string CodEmpenho { get; set; }  
  12.         public virtual string CodClientCTX { getset; }  
  13.         public virtual string IdtDocument { getset; }  
  14.         public virtual string YearExerciseCTX { getset; }  
  15.         public virtual string CodRanking { getset; }  
  16.         public virtual string CodDocument { getset; }  
  17.         public virtual string CodUg { getset; }  
  18.         public virtual string YearDocument { getset; }  
  19.   
  20.   
  21.         public override bool Equals(object obj)  
  22.         {  
  23.             //return AnoExercicio.ToString() == CodCliente.ToString() == CodGrupoFonte.ToString() == CodFonte.ToString();  
  24.             if (!(obj is EmpenhoDTO)) return false;  
  25.   
  26.             var objA = obj as EmpenhoDTO;  
  27.             return (this.YearExerciseCTX == objA.YearExerciseCTX && this.CodClientCTX == objA.CodClientCTX && this.IdtDocument == objA.IdtDocument &&   
  28.                 this.CodDocument ==objA.CodDocument && this.CodUg==objA.CodUg && this.YearDocument ==objA.YearDocument );  
  29.                          
  30.   
  31.         }  
  32.   
  33.         public override int GetHashCode()  
  34.         {  
  35.             return base.GetHashCode();  
  36.         }  
  37.     }  
  38. }  

Answers (3)