Hi,
I try to do a filter on a string array, but I get a strange result.
Here my code :
And this is the result :
What’s wrong ?
Thanks
@deid Select
returns IEnumerable
, so you should use the following syntax:
<<var [res = structEnDur.Where(i => i == “CIAO”).Select(r => r)]>>
<<foreach [item in res]>>
<<[item]>>
<</foreach >>
Or
<<var [res1 = structEnDur.Where(i => i == “CIAO”).FirstOrDefault()]>>
<<[res1]>>
@alexey.noskov
Thanks for your fast reply. Your suggestion works perfectly.
But, when I try to do the same thing with an object I have some difficult.
For example, I have this code :
and it returns this :
But, when i try to apply a filter like this :
I get this error :
Thank you
@deid Unfortunately, I cannot reproduce the problem on my side. Here is test template and code:
List<Dummy> data = new List<Dummy>();
data.Add(new Dummy() { Name = "First", Volume = 1 });
data.Add(new Dummy() { Name = "Second", Volume = 2 });
data.Add(new Dummy() { Name = "Third", Volume = 3 });
data.Add(new Dummy() { Name = "Fourth", Volume = 4 });
Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, data, "data");
doc.Save(@"C:\Temp\out.docx");
public class Dummy
{
public string Name;
public double Volume;
}
in.docx (13.4 KB)
out.docx (10.3 KB)
Could you please attach your sample template and data that will allow us to reproduce the problem.
@alexey.noskov
Thank you for your test Alexey. Unfortunately, I can’t access to the code behind. I have template access only.
@deid The error message states that item
is string. What does the following return on your side?
<<foreach [item in res]>>
<<[item]>>
<</foreach >>
@alexey.noskov I’ve tested it and the error disappeared. However, there are no results displayed for <<[item]>>
@alexey.noskov Yes I suppose is that, but why ? The string in the where condition is exactly the same of the second element of my list
@deid I am afraid it is difficult to answer without your data. have you tried using another condition for testing purposes? For example, try using !=
instead of ==
and check the output.
@alexey.noskov Yes, good idea. I get this :
Exactly five elements. This mean that == operator doesn’t work.
But, when I try to get the name attribute from the IEnumerable, I have always this error :
@deid Please try using another variable name in your template. Change this:
<<var [res = structDyn.Where(f => f.boname != "BO BRUNSTATT CHASSE")
.Select(s => new {
name = (string)s.boname,
vol = s.maxvolume
})
]>>
To this:
<<var [res2 = structDyn.Where(f => f.boname != "BO BRUNSTATT CHASSE")
.Select(s => new {
name = (string)s.boname,
vol = s.maxvolume
})
]>>
res
variable name was already used in your template.