C# Linq to sum and group XML [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Hi guys I need some direction with how to layout a group and sum of a variable from within an XML file on C#.
The XML document is as follows:
<xxxx>
<yy>
<pp a= "b">
<aa> 3 </aa>
</yy>
<yy>
<pp a= "c">
<aa> 5 </aa>
</yy>
<yy>
<pp a= "b">
<aa> 6 </aa>
</yy>
</xxxx>
How would I go about creating a C# Linq query to group attributes(a) and sum the (aa) element totals?

Something like this?
from d in xmldoc.Descendants("yy")
group d by d.Element("pp").Attribute("a").Value into dg
select new { a = dg.Key, sum = dg.Sum(d => Int64.Parse(d.Element("aa").Value)) }

Related

Get text patters from string using regular expression [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
In C# .NET
I have a string with
PSL44T-VK5VF-2B
PSL-44TVK5-VF2B
PS-L44-TVK-5VF-2B
using regular expression can I get the result format as
XXXXXX-XXXX-XX <- PSL44T-VK5VF-2B
PSL-XXXXXX-XXXX <- PSL-44TVK5-VF2B
XX-XXX-XXX-XXX-2B <- PS-L44-TVK-5VF-2B
XX-L44-XXX-XXX-XX <- PS-L44-TVK-5VF-2B
Your question is not clear. But if you want to filter a list of strings with regular expressions, you can do as follows:
List<string> inputs = new List<string>();
inputs.Add("PSL44T-VK5VF-2B");
inputs.Add("PSL-44TVK5-VF2B");
inputs.Add("PS-L44-TVK-5VF-2B");
var myRegex = new Regex("^PSL-.{6}-.{4}$"); // for PSL-XXXXXX-XXXX
List<string> resultList = inputs.Where(f => myRegex.IsMatch(f)).ToList();
and result:

C# Get Object Values [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm new to C#.
I have a method that returns an object with the List of objects inside.
0 {{DapperRow, RecordedFormID = 'id1'}} object {Dapper.SqlMapper.DapperRow}
1 {{DapperRow, RecordedFormID = 'id2'}} object {Dapper.SqlMapper.DapperRow}
How can I get those ids as strings?
Here is a screenshot
You can use System.Linq namespace and do this:
yourObject.Select(x => x.RecordedFormID);

How can I implement SQL statement to LINQ in MVC? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Good day
I need to interpret the following SQL to LINQ.
select
t1.req_no,
t1.seq_no,
t1.quantity,
t1.uom,
t1.item_name,
t2.event_date
from tb_cs_test t1, tb_cs_test2 t2 where (t1.req_no = 1 and t2.req_no = 1 );
I use MVC and with this SQL Statement i need to throw the requested fields based on the condition that I put
Thanks
You can do that with a JOIN:
from t1 in tb_cs_test
join t2 in tb_cs_test2
on t1.req_no equals t2.req_no
where t1.req_no = 1
select new {
t1.req_no,
t1.seq_no,
t1.quantity,
t1.uom,
t1.item_name,
t2.event_date
}

Usinq Linq to get rows based on comma-separated value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have comma-separated data in my column called col1, and I have an array of strings
IEnumerable<string> year = {"1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000"}
I have tried the following
searchfrom = searchfrom.Where(x => years.Contains(x.col1.Replace(',', ' '))).ToList();
and
searchfrom = searchfrom.Where(x => years.Contains(x.col1)).ToList();
I want that row which is match any "year" into "col1"
To optimize such queries, you should first convert your years collection into a hash set.
var years = new HashSet<string>(new [] { "1990", "1991", ... });
In your Where clause, you need to split the contents of each of your records, x, for which you can use x.Split(','). Then, you need to check whether any of these subparts are contained within the years collection.
var result = searchfrom.Where(x =>
x.Split(',').Any(years.Contains)
).ToList();

Outer apply in linq to sql [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
What's the linq to sql translation for this query
SELECT *
FROM MasterTable AS [t0]
Outer APPLY UfnGetDetail([t0].x, [t0].y, z) AS [t2]
...
Ok, it works with something like this
var query = from mt in db.MasterTable
let detailResult = db.UfnGetDetail(mt.x, mt.y, z).SingleOrDefault()...
Have you tried this:
from mt in dc.MasterTable
select dc.UfnGetDetail (mt.x, mt.y)

Categories