linq

Linq query across all sites and subsites on a sharepoint server?

I'm working on a webpart for a sharepoint 2010 installation. This has multiple sites, and each site has pages, and may have subsites, themselves with more pages and sites. I want to get a list of all pages in the entire installation that match a certain criteria (eg title == "Test"). I can do this using a CAML SPSiteDataQuery object an...

LINQ 2 Entities inverse navigation left join for 0..1-many

New to L2E, found out that I can't use DefaultIfEmpty() until I get L2E 4 (which will hopefully be happening soon). I found an article regarding left joins via inverse navigation, which seems like a clean method for left joins. That said, the article appears to be incorrect, in that the snippet from lPnpItem in PnpItems join lPnpItemVa...

LINQ Count .. best method

My company has just started using LINQ and I still am having a little trouble with the abstractness (if thats a word) of the LINQ command and the SQL, my question is Dim query = (From o In data.Addresses _ Select o.Name).Count In the above in my mind, the SQL is returning all rows and the does a count on the numb...

Create tree hierarchy in JSON with LINQ

I have a flat list of some names in a random order. Is it possible to write a single LINQ statement to create a tree hierarchy in JSON so that they would be grouped according to the rules illustrated by the example below: Input: "Banana", "Apple", "Cheery", "Lemon", "Orange", ... Output: { "A, B, C": "Apple, Banana, Cherry", ...

How to check if all of the elements in a list return true for a property using Linq?

I would like to have a LINQ statement that calls the property IsValid. If all elements returned true, I want the statement to return true as well. How can it be done? ...

Help sorting XML Data in .NET (maybe with LINQ query?)

I have this hierarchy of XML <Chapters> <Chapter @num=""> <Section @letter=""> <Heading @num="" /> </Section> </Chapter> </Chapters> I need to do a sort so that all chapters are sequenced in ascending order, each section within that chapter is sequenced in ascending order, and each heading in that section is sor...

Group and aggregate a list of objects

Hi, I have a list of data structured like this: Field1 Field2 Field3 1 1 "abc" 1 1 "def" 1 2 "123" 1 2 "456" I want to be able to merge this data so I end up with a single record per Field1 & Field2 and with the Field3 data concatenated. So in the above case I would get: Field1 Field2 Field3 1 1 "abcdef" 1 2...

algorithm challenge: merging date range

I'm facing an interesting problem: I have several date ranges that can overlap each of them has a name Is it possible to "des-overlap" theses ranges? That is, to generate: a new set of ranges where none overlaps the others each of this new range has a list of corresponding names Maybe I can make this a bit more graphical. This i...

XNA and Linq on Xbox360

Please excuse the newbie question but I was wondering if I used Linq in my XNA application, would this still work on the Xbox 360? ...

Linq statement faster than foreach loop

I am writing a Mesh Rendering manager and thought it would be a good idea to group all of the meshes which use the same shader and then render these will I'm in that shader pass. I am currently using a foreach loop, but wondered if utilising Linq might give me a performance increase? ...

C# Sort list, Logical Compare

hello all , i have the following problem I have a list with strings for example (100_1, 100_2 .... , 100_10) I sort the list with following code extraImgsRaw.Sort((photo1, photo2) => photo1.CompareTo(photo2)); the result of this is : 100_1, 100_10, 100_2, 100_3 and so on the result that I want is a logical compare like 100_1, 100_2 ...

How can i use FindControl method in asp.net?

How can i use findControl and how can i get id's according to FindControl method? i need to get all TextBox data there are 40 textbox. And TextBoxid data... i reall want to learn also linq method ;) protected void Button1_Click(object sender, EventArgs e) { // SetRecursiveTextBoxAndLabels(PlaceHolder1); ...

linq to sql generates an faulting connectionstring

hi! Started working after some days off, and generated a new dbml file through vs 2008. then it sent an error: Object reference not set to an instance of an object. MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("C__USERS_JIMMY_DOCUMENTS_VISUAL_STUDIO_2008_WEBSITES_LUNCHGUIDEN_APP_DATA_LUNCHGU"& _ row 88:...

How can I use linq to return integers in one array that do not match up with an integer property of another array?

I have the following method signature: internal static int[] GetStudentIDsThatAreNotLinked(PrimaryKeyDataV1[] existingStudents, IQueryable<Student> linkedStudents) PrimaryKeyData is a class that has ServerID and LocalID integers as properties. Student is a class that (among other properties) has an integer one called StudentID...

Using Linq expressions as a specification pattern with parent/child query

I'm trying to use the specification pattern implemented as a Linq expression so that Linq providers can parse it to produce efficient database queries. This gives the basic idea. I am having a hard time trying trying to get it working with a parent/child query class Parent { public int Foo; public IList<Child> Children = n...

Why is this LINQ so slow?

Can anyone please explain why the third query below is orders of magnitude slower than the others when it oughtn't to take any longer than doing the first two in sequence? var data = Enumerable.Range(0, 10000).Select(x => new { Index = x, Value = x + " is the magic number"}).ToList(); var test1 = data.Select(x => new { Original = x, Mat...

how to use a delegate to get by name a CompiledQuery

I'm trying to find and run a CompiledQuery given the name. How do I access the compiled query by name and how do I then invoke the delegate? Here's as far as I can get - I get the error 'Error binding to target method' public class ActivityRepository { private readonly ActivityDataContext _db; public ActivityRepository() {...

garbage collection in a linq query

I have a question about how garbage collection might be handled in a linq query. Suppose I am given a list of requests to process. Each request generates a very large set of data, but then a filter is applied to only keep critical data from each requested load. //Input data List<request> requests; IEnumerable<filteredData> results = re...

How do I combine multiple linq queries into one results set?

I have a multi-select checkbox. Depending on which one is checked, I want to combine the results into a single query. Sort of like: if (Checkbox1.Checked) { var query1 = from t in table1 ... } if (Checkbox2.Checked) { var query2 = from t in table2 ... } DataGridView1.DataSource = query1.Union(query2); // obviously doesnt ...

Using LINQ to find keyword in all properties in object graph

I have a survey that's stored in a large object graph of variable depth, depending on how many sections and sub-sections the user chooses to create. I need to be able to search through all the properties for each object in the object graph and see if that property's .ToString() contains a certain keyword that's being searched for. Can I...