linq

LINQ- comparison & updating values

Probably this question was already asked before, but my google-fu and SO-Search did not get me what what I was looking for. I have a custom class, and a custom class comparer (for checking the equality of the class) implemented with IEqualityComparer. public class Person { public string Name { get; set; } public bool Fl...

joining in Linq

When i declare int[] a = { 1, 2 ,10,30}; int[] b = { 10, 20, 30 }; var q = from item1 in a join item2 in b on item1 equals item2 into g select g 1)What is actually getting selected into g ? It is difficult to understand the into keyword. if you g...

Linq - how to combine two enumerables

How to modify version 2 to produce the same result as version 1,because in version 2 i am getting cretesian product. int[] a = { 1, 2, 3 }; string[] str = { "one", "two", "three" }; Version 1 var q = a.Select((item, index) => new { itemA = item, itemB = str[index] }).ToArray(); version 2 var query = from i...

LINQ to Active Directory for accessible files

I am new to active directory and I am trying to put together a query that will return list of users and groups who have permissions to read the contents of any accessible file. I can not find any samples that deal with files. So I am at a lost on how to start. ...

N-way intersection of sorted enumerables

Given n enumerables of the same type that return distinct elements in ascending order, for example: IEnumerable<char> s1 = "adhjlstxyz"; IEnumerable<char> s2 = "bdeijmnpsz"; IEnumerable<char> s3 = "dejlnopsvw"; I want to efficiently find all values that are elements of all enumerables: IEnumerable<char> sx = Intersect(new[] { s1, s2,...

ASP.NET LINQ Database vendors

Will Linq work against any database (i.e) MySQL,Sybase,Oracle,DB2? ...

Two methods that differ only in LINQ where part - delegate?

I have a method: internal List<int> GetOldDoctorsIDs { var Result = from DataRow doctor in DoctorTable.Rows where doctor.Age > 30 select doctor.ID List<int> Doctors = new List<int>(); foreach (int id in Result) { //Register getting data Database.LogAccess("GetOldDoctors...

Easiest way to check numbers

I have a string array. What is the simplest way to check if all the elements of the array are numbers string[] str = new string[] { "23", "25", "Ho" }; ...

Linq grouping .include("Table") returning null on Table

I have a linq query that is grouping by answers by QuestionGroup. I need to have the table AssessmentQuestionsReference load so that i can bind to it in my WPF app. var groupedAnswers = from a in App.ents.AssessmentAnswers.Include("AssessmentQuestions") where a.Organisations.OrganisationID == App.selectedOrga...

Table not getting updated while using LinQ

Hello, I am trying to update a table using LinQ. Though records are getting inserted, for some reason they are not getting updated. what can be possible problem Dim db as new empDataContext Dim emptable as new employee if update then emptable=GetEmp(txtempID.Text) emptable.Name="Test" emptable.Age=11 emptable.City="NYC" else emptable...

Remove the duplcated element and then sort them with Linq

I have an XML file : <School> <SchoolID>9</SchoolID> <SchoolID>3</SchoolID> <SchoolID>3</SchoolID> <SchoolID>3</SchoolID> <SchoolID>4</SchoolID> <SchoolID>1</SchoolID> <SchoolID>3</SchoolID> <SchoolID>9</SchoolID> <SchoolID>2</SchoolID> </School> The expecting results should be like: <School>...

How to merge result IQueryable<T> together?

If I get two result IQueryable from different linq Query and I want to merge them together and return one as result, how to to this? For example, if: var q1 = (IQueryable<Person>).....; var q2 = (IQueryable<Person>).....; how to merge q1 and q2 together and get result like var q = (IQueryable<Person>)q1.Union(q2); ...

How to use If statement during select from Linq to Datasets

I have this LINQ statement Dim Demo = From d In DBDataTable.AsEnumerable _ Select id = d.Field(Of Integer)("id"), _ Colun = d.Field(Of Object) (_column2), _ Col3 = d.Field(Of Object)(_column3), _ Col4 = IIf(_Col4 <> -1, d.Field(Of Object)(_Col4), Nothing) Is there any wa...

Can Distinct be expressed using so-called embedded query rather than a method call

given the following code: string[] colors = {"red","green","blue","red","green","blue"}; var distinctColors = (from c in colors select c).Distinct(); distinctColors.Dump(); Is it possible to fold the call .Distinct() into the embedded query syntax? something like int T-SQL select distinct color from TableofColors ...

C# Sequence selection

Just I want to find any of the intColl of CustomerData is of single digit in length and select that customerData. List<CustomerData> cdata = new List<CustomerData>(); cdata.Add( new CustomerData { Key = 1, Name = "Marc", intColl = new List<int>() { 1, 2, 3 } } ...

Pass in Array to Select Case

Hi, this may be a dense question and I'm not finding it to be a dup of this one, but I need some help with understanding if an array can be used in a Select Case statement. I have a sub routine that I will create a string array dynamically. The XML is also listed, but it could be any of the values listed below. It will be something like...

Inline Select with LINQ

I need to replicate a T-SQL statement that has an inner select, using LINQ: SELECT *, CustomerTypes.Description as CustomerType, (Select Min(Distinct DocumentStatistics.StatDateTime) As LastStatCheck From DocumentStatistics Where DocumentStatistics.CustomerId = Customers.CustomerId) As LastStatCheck FROM Customers INNER JOIN Custome...

c# LINQ XML how to add function inside select query

select new FeedResource { Title = (string)details.Element("title"), Host = (string)details.Element("link"), Description = (string)details.Element("description"), PublishedOn = (DateTime?)details.Element("pubDate"), Generator = (string)details.Element("generator"), Language = (string)details.Element("language") ...

Delete records using LinQ

Hello, I have a gridview in asp.net page where I am allowing users to update data in the gridview with textboxes and dropdownlist. When a user hits submit button I am trying to delete existing records and insert new records When I try the below mentioned code it is throwing out errors. Right now I am not infront of the dev box thats th...

The order of elements vary in an Iquerable, every time I query with the same condition

I am working on a ASP.NET MVC application where we have to write our own code for paging. And I see elements getting repeated on different pages. This is happening because the order of elements in the Iquerable varies randomly and one have to query the database for each page. I solved this problem by ordering the elements by date of cre...