linq

How to count number of similar name files in one Folder in File System using c#?

To get the details of files, Directory.Getfiles("DirectoryPath", "*.zip") is returning me the all the files in a directory. Each file has a DateTime stamp in the Filename as a Postfix: e.g. {87fbf03b-ec94-44a0-aac5-ffbaf6416700}_20100204_145154634008919142146021.zip I am splitting out the GUID from the above file name. string ...

Get all the text under a element

My xml looks like this <Element> text <B>text<B></Element> Unknown number of B tags or tags even of a different name. How do i get the text from these? so it would be like this text text using linq to xml ...

Enumerable.Sum() overflowing

Hey, I'm using the Enumerable.Sum() extension method from LINQ to compute hash codes, and am having a problem with OverflowExceptions when the code gets big. I tried putting the call in an unchecked block, but that didn't seem to help. The MSDN documentation for the method says it will throw if the value gets too big, but I checked in ...

How to sort XML in LINQ C# by an attribute value? Also MVC

(Using the latest MVC 2 RC 2) I'm trying to sort some XML in LINQ (C#) by an element's attribute's value... var sites = from s in xDoc.Element("sites").Elements("site") orderby s.Attribute("name") select s; But when I pass this to my View I get the exception: Exception Details: System.ArgumentException: At least one object must imple...

Grouping using LINQ

I'm having a heck of a time with transforming a simple SQL Query into a LINQ query(using vb btw) Here is my SQL: SELECT USRDEFND5 FROM int_gp_employee GROUP BY USRDEFND5 The xml looks like this: <int_gp_employee> <row> .... <usrdefnd5>Some GUID</usrdefnd5> </row> </int_gp_employee> I've tried a number of di...

Can I have an incrementing count variable in LINQ?

I want to do something like this: from a in stuff let counter = 0 select new { count = counter++, a.Name }; But I get a error telling me that counter is read only. Is there a way to do something similar to this, without declaring a variable outside of the query? Basically, I just want to show a count/index column in LINQPad (which is...

DateTime Comparison in LINQ

I am ran into the following issue. Take a look at the following where clause. Where(x => x.CreateTS <= dateParameters.CreationDate.ToDateValue && x.CreateTS >= dateParameters.CreationDate.FromDateValue) CreateTS is a Timestamp column in the table. so when my dateparameters are todate = 01/28/2010 12:00A.M" fromdate= "01/2...

How do I preserve whitespace characters when parsing XML from C# LINQ

What do I need to do in either my C# code or my XML document so that the XDocument parser reads literal whitespace for Values of XElements? Background I have an XML document, part of which looks like this: <NewLineString>&#10;&#13;</NewLineString> <IndentString> </IndentString> I'm adding the values of each XELement to a...

Find all child controls of specific type using Enumerable.OfType<T>() or LINQ

Existed MyControl1.Controls.OfType<RadioButton>() searches only thru initial collection and do not enters to children. Is it possible to find all child controls of specific type using Enumerable.OfType<T>() or LINQ without writing own recursive method? Like this. ...

Get the depth of an Item

I have xml like this: <A><B>test</B><B><B>test2</B></B><B><B><B>test2</B></B></B></A> How can I get the level of each of these items using linq to xml level of test=1 level of test2=2 level of test3=3 I have no idea how many nodes there will be or how many levels there will be. I can write this as a recursive function but I thought...

A better way than nesting foreach?

I've got a list of Radios that I'm trying to produce a more user-friendly version of. Behind the scenes all descriptions are stringIds and all part numbers are DB Ids. Right now, I've got this code: var z = (from w in wireless join s in allStrings on w.DescriptionId equals s.StringId ...

How to load an XHTML file into an XElement using a custom XmlUrlResolver?

I am trying to get an XHTML file loaded into an LINQ XElement. However, I am running into problems with the resolver. The problem has to do with the following definition: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; I have a custom XmlUrlResolver with an o...

LINQ context SubmitChanges

Regarding the SubmitChanges order (Insert, Update, Delete), is there a way to change that order? I need to have the Deletes executed first, any updates, then any new inserts. I have a datagrid where the user can do all add, changes and updates and submit. Since each grod row must have a unique item chosen in it (via a dropdown), it's pos...

Can I cast a LINQ query result to BindingList<T>?

Hi, From what I've learned, you can't cast to BindingList, but rather you can wrap your result from the Linq query with a NEW BindingList. However, this doesn't work for me, because my Original Binding list has some events attached to it and i would like to maintain the same events in my LINQ result set. For example: I have my main B...

How do I search just the children of an XDocument, rather than all of its descendants?

I can't seem to find anything other than XDocument.Descendants () in the documentation. Is there any way to do this? ...

How can I select objects sub members with linq?

Let's say I have class objectA { string name; } class objectB { List<objectA> la = new List<objectA>(); } main() { List<objectB> lb = new List<objectB>(); /*some operations that results in lb having many objectB objects and each objectB having many objectA. lb objectB1 objectA1 somestring1 objectA2 ...

linq searching matching items in child collection

Hi I am looking for a way to do a IN clause query on child collections in linq. I have a an example as follows: Entity: Product.CategoryAssignments - this is an IList<Category> that the product is assigned to. Product can be assigned to multiple categories. I want to retrieve all products matching in a list of categories i.e. ILis...

restrict num of items loaded in navigation property

Hi All, I have the following query in Linq: var query = from question in context.Questions.Include("QAnswers") join answer in context.Answers on question.id equals answer.qst where answer.user == param_userID select question; return query.toList(); The problem is that it doesn't...

Do linq generated queries get cached effectively by SQL Server 2008?

Do linq generated queries get cached effectively by SQL Server 2008? or is it better to use stored procedures with linq or what about a view and then using compiled linq queries... opinions? cheers emphasis here is on "effectively", and or is it better.... ie. views are cached well by sql server, and then using linq on the view.... ...

Multiple Left Joins against Entity Framework

I've been looking but can't find a solution to this... Here are my Entities... ContentPage (has many ContentPageZones) ContentPageZone (Has One Content) Content I want to query for a ContentPage by ID , and, I want it to contain all related ContentPageZones that are active and that have at least one Content that is active (both have...