linq-to-objects

Get grouped comma separated values with linq

☆樱花仙子☆ 提交于 2020-08-24 06:33:06
问题 I would like a third column "items" with the values that are grouped. var dic = new Dictionary<string, int>(); dic.Add("a", 1); dic.Add("b", 1); dic.Add("c", 2); dic.Add("d", 3); var dCounts = (from i in dic group i by i.Value into g select new { g.Key, count = g.Count()}); var a = dCounts.Where(c => c.count>1 ); dCounts.Dump(); a.Dump(); This code results in: Key Count 1 2 2 1 3 1 I would like these results: Key Count Items 1 2 a, b 2 1 c 3 1 d 回答1: var dCounts = (from i in dic group i by i

LINQ to Objects Join two collections to set values in the first collection

那年仲夏 提交于 2020-06-24 19:34:26
问题 I have the following Entity Framework query: var results = from r in db.Results select r; I'm using AutoMapper to map to another type: var mapped = Mapper.Map<IEnumerable<Database.Result>, IEnumerable<Objects.Result>>(results); In my Objects.Result type, I have a property called reason that is not coming from the database. It is coming from another source that I need to basically populate back into my mapped type: var reasons = new List<Reason> { new Reason { Id = 1, Reason = "asdf..." } }; I

How do i get the difference in two lists in C#?

梦想的初衷 提交于 2020-02-10 09:00:16
问题 Ok so I have two lists in C# List<Attribute> attributes = new List<Attribute>(); List<string> songs = new List<string>(); one is of strings and and one is of a attribute object that i created..very simple class Attribute { public string size { get; set; } public string link { get; set; } public string name { get; set; } public Attribute(){} public Attribute(string s, string l, string n) { size = s; link = l; name = n; } } I now have to compare to see what songs are not in the attributes name

How do i get the difference in two lists in C#?

二次信任 提交于 2020-02-10 08:59:25
问题 Ok so I have two lists in C# List<Attribute> attributes = new List<Attribute>(); List<string> songs = new List<string>(); one is of strings and and one is of a attribute object that i created..very simple class Attribute { public string size { get; set; } public string link { get; set; } public string name { get; set; } public Attribute(){} public Attribute(string s, string l, string n) { size = s; link = l; name = n; } } I now have to compare to see what songs are not in the attributes name

LINQ dynamic property in select

我的未来我决定 提交于 2020-01-25 02:00:06
问题 // Hi everyone i do this call in Action : [HttpGet] public virtual ActionResult JsonGetProvinces(int countryId) { //WebSiteContext WbContext = new WebSiteContext(); //UnitOfWork UnitofWork = new UnitOfWork(WbContext); var provinces = ( from province in unitofWork.ProvinceRepository.All where province.CountryId == countryId select new { Id = province.Id, Name = province.GetType().GetProperty("Name_" + CultureManager.GetCurrentCultureShortName()).GetValue(province) } ).ToList(); return Json

LINQ to Objects - Does Not Contain?

邮差的信 提交于 2020-01-24 17:22:08
问题 I have a collection of Items that each have a collection of Relationships. I have a list of Groups that Items can have Relationships with. I can find all the Items that have a particular relationship but I now want to find all the Items that don't have a Relationship with any of my Groups. I can find the Items that have a relationship with any of the Groups by doing this: Dim groupIds as List(of Integer) = (From g In cmdbGroups Select g.ID).ToList Dim haveGroup = (From item In items _ Where

Return Max value with LINQ Query in VB.NET?

牧云@^-^@ 提交于 2020-01-23 12:24:10
问题 I have a method that takes in an id, a start date, and and end date as parameters. It will return rows of data each corresponding to the day of the week that fall between the date range. The rows are all doubles. After returning it into a DataTable, I need to be able to use LINQ in VB.NET to return the maximum value. How can I achieve this? Here is the initial setup? Dim dt as DataTable = GetMaximumValue(1,"10/23/2011","11/23"/2011") 'Do linq query here to return the maximum value The other

Using LINQ to get the difference between two list of objects based only on a single object property [closed]

非 Y 不嫁゛ 提交于 2020-01-23 11:41:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . the dog class has two properties (name and color) Let's say I have two IEnumerable lists: List1 [{name="Sam", color="Fawn"}, {name="Mary", color=""}, {name="Bob", color=""}] List2 [{name="Mary", color="Black"},{name="Bob", color="Yellow"}] I want to get a list of dog objects that differ ONLY in name so my return

LINQ Join inside Join, how to?

僤鯓⒐⒋嵵緔 提交于 2020-01-17 03:01:05
问题 I am new to LINQ. I am using LINQ to Objects (I think) and the way the data is set up I can't directly get to a piece of data I need. This is the general structure of what I NEED to do: FROM Project LEFT OUTER JOIN TechnologySectors LEFT OUTER JOIN SelectedAgencies LEFT OUTER JOIN ProjectStatus JOIN Process I need a single piece of data from Process. So far I have figured out how to do a LEFT OUTER JOIN with LINQ using DefaultIfEmpty() but I cannot figure out out to get Process to JOIN with

Parallel.ForEach throws exception when processing extremely large sets of data

怎甘沉沦 提交于 2020-01-14 03:59:14
问题 My question centers on some Parallel.ForEach code that used to work without fail, and now that our database has grown to 5 times as large, it breaks almost regularly. Parallel.ForEach<Stock_ListAllResult>( lbStockList.SelectedItems.Cast<Stock_ListAllResult>(), SelectedStock => { ComputeTipDown( SelectedStock.Symbol ); } ); The ComputeTipDown() method gets all daily stock tic data for the symbol, and iterates through each day, gets yesterday's data and does a few calculations and then inserts