linq-to-objects

Replacing nested foreach with LINQ; modify and update a property deep within

Consider the requirement to change a data member on one or more properties of an object that is 5 or 6 levels deep. There are sub-collections that need to be iterated through to get to the property that needs inspection & modification. Here we're calling a method that cleans the street address of a Employee. Since we're changing data ...

Extension method for UPDATE in Linq to Objects

In the following scenario, I am querying a List object and for the matching predicate I want to update some values: var updatedList = MyList .Where (c => c.listItem1 != "someValue") .Update (m => {m.someProperty = false;}); The only issue is there is no Update extension method. How to go about this?...

Generic LINQ function - SelectMany with selection Func as a parameter

I've got a class with many string arrays. I'd like to have one generic function which can get me a unique List<string> for a given property. Example: public class Zoo { string Name { get; set;} string[] Animals { get; set;} string[] Zookeepers { get; set;} string[] Vendors { get; set;} } I'd like to have a generic functio...

How linq 2 sql is translated to TSQL

Hi all, It seems Linq2sql doesn't know how to construct the TSQL while you transform linq2sql object into domain object with constructors. Such as: from c in db.Companies select new Company (c.ID, c.Name, c.Location).Where(x => x.Name =="Roy"); But when using settable attributes, it will be OK. from c in db.Companies select new Comp...

When not to use LINQ To Objects?

When should I NOT use LINQ To Objects? The inverse of this question has been asked, but didn't cover when not to use L2O. ...

Creating Key/Value collections using LINQ To Objects

I'm trying to use LINQ To Objects to create a query that will give me files, indexed by filename with a value mapping to their binary data as byte[]. However I can't find a 'neat' way to do this. I'm hoping to get something like a Dictionary<T,K> output. Here's what I have so far. Example delimFileNames="1.jpg|2.jpg" //Extract filenam...

How to get Lamda in LINQ to actually filter for dynamic linq

Example-I have a person class Public Class Person Private _fname As String Public Property Fname() As String Get Return _fname End Get Set(ByVal value As String) _fname = value End Set End Property Private _lname As String Public Property Lname() As String Get Return _lname End Get S...

Need help with LINQ query that joins two tables containing periodic events

My real-life example is too obscure to explain, but this is a pretty good approximation of what I'm trying to do... Month table has columns: Id, Name Holiday table has columns: Id, MonthId, DayOfMonth, Name Appointment table has columns: Id, MonthId, DayOfMonth, Description How do I produce a list of unique events (holidays and appoi...

Is there a extension library specifically for LINQ to Objects?

This question comes as a logical follow-up to one of my earlier questions: Extension method for UPDATE... I would like to know if there is a library specific for LINQ to Objects ... more specifically a set of useful extensions for IEnumerable ? Here ... I do not want to know about the SQL entity or XML related extensions. Is there an ...

DataTable Select vs LINQ Select

Any advice on when DataTable.Select should be used versus LINQ Select when dealing with an in-memory DataTable? I find LINQ syntax easier and more powerful, but I'm not sure if there are performance or other issues which make a DataTable select preferable. (I'm using a third party API that provides a DataTable that has been pre-populat...

linq to objects - set object property to null if it equals "folder"

Hi, I have a collection of objects, representing a folder structure. I'd like to set the property "FileExtenson" to null, if its a folder. This is as far as I've got. Can anyone help? var items=MyClass.All().ToList(); items.ForEach(x=>x.FileExtension = string.empty).Where(y=>y.FileExtension == "folder").ToList()); Frank ...

Can a single LINQ Query Expression be framed in this scenario?

I am facing a scenario where I have to filter a single object based on many objects. For sake of example, I have a Grocery object which comprises of both Fruit and Vegetable properties. Then I have the individual Fruit and Vegetable objects. My objective is this: var groceryList = from grocery in Grocery.ToList() fr...

Linq-to-objects processing time doubles per x iterations

I have a list of entites that contains ~137000 records that I loop through I then need to linq to a list of Tuple of additional params this contains ~ 150000 Why does it keep taking longer, the more iterations it does? Here is from the stopwatch Found: 136770 items that match the criteria. 10,000 items processed EllapsedTime: 5473Th...

Confused about how to implement extension methods in LINQ to Objects

Hi all, Fairly new to LINQ and trying to wrap my head around extension methods. What I'm attempting to do: 1) Have a table with three columns, col1 (string), col2 (double), col3 (DateTime) table1.Rows.Add("string 1", 1, new DateTime(2009, 01, 01)); table1.Rows.Add("string 1", 2, new DateTime(2009, 02, 01)); tab...

LINQ identity function?

Just a little niggle about LINQ syntax. I'm flattening an IEnumerable<IEnumerable<T>> with SelectMany(x => x). My problem is with the lambda expression x => x. It looks a bit ugly. Is there some static 'identity function' object that I can use instead of x => x? Something like SelectMany(IdentityFunction)? ...

How to use a Distinct on a column using Linq

Here is my code: var query = from row1 in table.AsEnumerable() let time = row1.Field<DateTime>("time") let uri = row1.Field<string>("cs-uri-stem") let ip = row1.Field<string>("c-ip") let questionid = row1.Field<int>("questionid") ...

Combine multiple objects for insert into one table using Linq

I want to insert into one table from the properties of multiple classes using Linq. Here are some representations of my objects( I am custom creating my Linq Objects with the attributes): <Table(Name:="Certificates")> _ Public Class Certificate : Implements ICertificate, INotifyPropertyChanged <Column(CanBeNull:=False, IsDbGenerated...

How to get All select keys in Linq Group By Clause

I am trying to get the rest of the select keys in this linq query but the intellisense is giving me an error var query2 = from row2 in query1 group row2 by row2.questionid into g where g.Count() > 0 select new { questionid1, //...

LINQ Gernic List VB.NET

Hi Guys, I am trying to create a domain model using a product class entity an Abstract repository and a fake repository with sample data. I have created the following product class Namespace Entities Public Class Product Dim _ProductID As Integer Dim _Name As String Dim _Description As String Dim _Price As Decimal D...

2.How to edit/update records from the database using textbox by linq to sql?

I'm using visual basic 2008 express edition by linq to sql for my database operation such as edit records. I did not use any sql server but I'm just using the built-in sql server within the visual basic 2008 express. I tried to revised the codes, no error in syntax but there's an error at runtime and it pops-up a window message saying it...