fantamen
asked on
Linq Int concatenation
In below piece of code the problem is in this row: (Par_TabNumOrd.Contains((I nt32) (c.TabellaOrdine.ToString( ) + c.NumeroOrdine.ToString()) ))
Parameter Par_TabNumOrd contains a list of unions between two integer information: TabellaOrdine and NumeroOrdine. In the linq query there are two corresponding fields of entity dbProduzContext.vi_Carichi . I've to concatenate fields but my solution is not correct. What can I do?
Parameter Par_TabNumOrd contains a list of unions between two integer information: TabellaOrdine and NumeroOrdine. In the linq query there are two corresponding fields of entity dbProduzContext.vi_Carichi
public List<DatiCaricoRpt> GetDettaglioColliDaProdurreDelCarico(Int32 Par_IDPianoCarico, string Par_Lista, List<Int32> Par_TabNumOrd)
{
using (var dbProduzContext = new ProduzModel.ProduzContext())
{
// Uso un join di tipo "left join" fra Carichi.CodiceArticolo e AnagArt.CodiceArticolo.
var results = from c in dbProduzContext.vi_Carichi
join a in dbProduzContext.vi_AnagArt on c.CodiceArticolo equals a.CodiceArticolo
into a1
from a2 in a1.DefaultIfEmpty()
join ps in dbProduzContext.Carichi_PadriStazioni on c.NumeroColli equals ps.IDCollo
join sa in dbProduzContext.AnaStati_Avanzamento on ps.IDStatoAvanzamento equals sa.IDStatoAvanzamento
where (c.Lista == Par_Lista) &&
(ps.IDPianoCarico == Par_IDPianoCarico) &&
(ps.PgrCollo == 1) &&
(ps.IDLinea == Pubblici.pvclParametri.IDLinea) &&
(ps.IDStazione == Pubblici.pvclParametri.CodStazione) &&
(Par_TabNumOrd.Contains((Int32) (c.TabellaOrdine.ToString() + c.NumeroOrdine.ToString()))) &&
((ps.IDStatoAvanzamento == (Int16)Class_Costants.pvStatoAvanzamentoCollo.DaProdurre) |
(ps.IDStatoAvanzamento == (Int16)Class_Costants.pvStatoAvanzamentoCollo.Ritardatario) |
(ps.IDStatoAvanzamento == (Int16)Class_Costants.pvStatoAvanzamentoCollo.Escluso))
orderby c.Consegna ascending, c.UnioneColli ascending
select new DatiCaricoRpt
{
Consegna = (Int16)c.Consegna,
TabellaOrdine = (Int16)c.TabellaOrdine,
NumeroOrdine = (Int32)c.NumeroOrdine,
IDStatoAvanzamento = ps.IDStatoAvanzamento,
IDStatoAvanzamentoD = sa.Descrizione,
NumeroColli = (Int16)c.NumeroColli,
UnioneColli = (Int16)c.UnioneColli,
CodiceArticolo = c.CodiceArticolo,
Qta = (float)c.Quantita,
DescrizioneArticolo = a2.DescrizArticolo,
DescrizAggiuntiva1 = a2.DescrizAggiuntiva1
};
return results.ToList();
}
ASKER
Hi Jaime
I give you an example: parameter Par_TabNumOrd has a list of values values (101044765, 101006712, 102003499). First three positions of each value express TabellaOrdine (101) and the others express NumeroOrdine (44765)
In query linq I've to filter entity dbProduzContext.vi_Carichi by the parameter list. dbProduzContext.vi_Carichi has fields TabellaOrdine (int16) and NumeroOrdine (int32).
Thank you
I give you an example: parameter Par_TabNumOrd has a list of values values (101044765, 101006712, 102003499). First three positions of each value express TabellaOrdine (101) and the others express NumeroOrdine (44765)
In query linq I've to filter entity dbProduzContext.vi_Carichi
Thank you
c.NumeroOrdine.ToString() won't add leading zeros to the string, so you won't get a match when the value is shorter than 6 digits, e.g. 44765
Adding a format code - c.NumeroOrdine.ToString("D 6") - should fix that in your current code.
An alternative approach is to use String.Format:
String.Format({"{0:D3} {1:D6}", c.TabellaOrdine, c.NumeroOrdine) will produce the concatenation you want
Adding a format code - c.NumeroOrdine.ToString("D
An alternative approach is to use String.Format:
String.Format({"{0:D3} {1:D6}", c.TabellaOrdine, c.NumeroOrdine) will produce the concatenation you want
ASKER
Hi Mike
I've take another way to solve my problem because of the urgency to complete the procedure.
Anyway I've tried you suggestions, this is the result:
1. c.NumeroOrdine.ToString("D 6") ... return the error no overload for method "string" takes 1 arguments
2. String.Format({"{0:D3} {1:D6}", c.TabellaOrdine, c.NumeroOrdine) ... return the errore string.format is not recognize in linq ....
By
I've take another way to solve my problem because of the urgency to complete the procedure.
Anyway I've tried you suggestions, this is the result:
1. c.NumeroOrdine.ToString("D
2. String.Format({"{0:D3} {1:D6}", c.TabellaOrdine, c.NumeroOrdine) ... return the errore string.format is not recognize in linq ....
By
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for the calculation suggestion to obtain formatted string.
Could you give real examples of what you are trying to achieve with that line?