linq-to-objects

Specify task timeout in parallel linq to objects

一笑奈何 提交于 2020-01-13 03:48:24
问题 I have a list of Pictures that I want to process in parallel, but with a timeout. My old code did this by paging through the items and using WaitHandles, but I want to use the new Parallel Linq or Tasks library available in .Net 4. The following snippet is working, how do I add a timeout to it? (Timeout would be for each task executing, not a timeout for all items to be processed) private PictureList FetchPictures(List<Picture> wallResults) { wallResults .AsParallel() .WithDegreeOfParallelism

Query objects for one to many relationship in LINQ

自作多情 提交于 2020-01-06 07:54:35
问题 I have a problem which seems to be quite similar to Query objects for one to many relationship in LINQ I've been trying to solve my problem referring the above but somehow I've been failing for a long time. The scenario I have a model named Business which has a ICollection of Branches and also the business belongs to a particular SubCategory . The model Looks something like public class SubCategory { public string Id { get; set; } public string Name { get; set; } public string Description {

Query objects for one to many relationship in LINQ

Deadly 提交于 2020-01-06 07:54:11
问题 I have a problem which seems to be quite similar to Query objects for one to many relationship in LINQ I've been trying to solve my problem referring the above but somehow I've been failing for a long time. The scenario I have a model named Business which has a ICollection of Branches and also the business belongs to a particular SubCategory . The model Looks something like public class SubCategory { public string Id { get; set; } public string Name { get; set; } public string Description {

Dealing with LINQ / HttpContext.Application & WebServices

醉酒当歌 提交于 2020-01-06 07:15:35
问题 I have the following function + code to parse and query a webservice request then in theory store the results in the application (as it only needs to refresh once a day, which luckily is when the application refreshes). //tocommondata is a reference to the common stuff in the webservice var dCountries = toCommonData.PropertyCountries; //KeyValuePair var dRegions = toCommonData.Regions;//Array var dAreas = toCommonData.Areas;//Array var commonDAT = (from c in dCountries join r in dRegions on c

LINQ Select Range Of Orders By Surname

江枫思渺然 提交于 2020-01-06 06:07:20
问题 I guess this is probably going to be obvious in retrospect but I am finding it very hard to get my head round this. Basically I just want to use LINQ to Objects to select from a range of objects with a surname property the surnames alphabetically between two surnames e.g. in the list: Adams Bentham Bickford Gillies Kelly Moore Peters Rutherford Smith Taylor Williams If you selected from "Kelly" to "Smith" it would return: Kelly Moore Peters Rutherford Smith inclusive. It has to be specific

Is there a more efficient method to find dupes in Sql server

偶尔善良 提交于 2020-01-06 04:28:28
问题 I have this question for which I provided a solution. However, I don't feel that is as efficient as it could be: using (DataContext context = new DataContext(SqlConnection) { var custInfo = context.GetTable<tbl_CustomerInfo>(); string compID = ImportCust.Rows[0]["CompanyID"].ToString(); var imports = from cust in ImportCust.AsEnumerable() select cust.Field<int>("CustomerID"); var dupes = from import in imports join cust in custInfo on import equals cust.CustomerID where cust.CompanyID==

Is there a more efficient method to find dupes in Sql server

别说谁变了你拦得住时间么 提交于 2020-01-06 04:28:10
问题 I have this question for which I provided a solution. However, I don't feel that is as efficient as it could be: using (DataContext context = new DataContext(SqlConnection) { var custInfo = context.GetTable<tbl_CustomerInfo>(); string compID = ImportCust.Rows[0]["CompanyID"].ToString(); var imports = from cust in ImportCust.AsEnumerable() select cust.Field<int>("CustomerID"); var dupes = from import in imports join cust in custInfo on import equals cust.CustomerID where cust.CompanyID==

Select All that do not already exist in destination

£可爱£侵袭症+ 提交于 2020-01-06 03:37:26
问题 I have a simple set of arrays, kind of like this .. structure shortened for brevity and such. Basically it is a list of identities with an additional field (a sort of dictionary). [ { "Id" : 1, "Requirement" : { "Value" : "2", "Name" : "Orders" } }, { "Id" : 2, "Requirement" : { "Value" : "4", "Name" : "Orders" } }, { "Id" : 3, "Requirement" : { "Value" : "6", "Name" : "Orders" } }, { "Id" : 4, "Requirement" : { "Value" : "8", "Name" : "Orders" } }, ] I need to be constantly checking another

Scope of Linq Expressions defined in a loop - At issue: closing over loop variable

纵然是瞬间 提交于 2020-01-04 11:39:27
问题 I have a scope question regarding Linq expressions that are defined in a loop. The following LinqPad C# Program demonstrates the behaviour: void Main() { string[] data=new string[] {"A1", "B1", "A2", "B2" }; string[] keys=new string[] {"A", "B" }; List<Result> results=new List<Result>(); foreach (string key in keys) { IEnumerable<string> myData=data.Where (x => x.StartsWith(key)); results.Add(new Result() { Key=key, Data=myData}); } results.Dump(); } // Define other methods and classes here

Determine whether two or more objects in a list are equal according to some property

好久不见. 提交于 2020-01-04 02:54:06
问题 Say I have a list List<MyObject> myObjectList . The MyObject object has a property named Order which is of type int . How can I determine whether two or more objects in myObjectList have the same Order using LINQ-to-objects? 回答1: First GroupBy MyObject.Order and then determine if Any of the groups have more than one member: bool b = myObjectList.GroupBy(x => x.Order) .Any(g => g.Count() > 1); // b is true is there are at least two objects with the same Order // b is false otherwise 回答2: bool