linq

C# Outer Apply in LINQ

How can I achieve Outer Apply in LINQ? I'm having a bit of a problem. Here's the SQL Query I'm using. SELECT u.masterID ,u.user ,h.created FROM dbo.Users u OUTER APPLY (SELECT TOP 1 * FROM UserHistory h where h.masterID = u.masterID ORDER BY created DESC) h ...

Translate an IQueryable instance to LINQ syntax in a string

I would like to find out if anyone has existing work surrounding formatting an IQueryable instance back into a LINQ C# syntax inside a string. It'd be a nice-to-have feature for an internal LINQ-to-SQL auditing framework I'm building. Once my framework gets the IQueryable instance from a data repository method, I'd like to output somethi...

LINQ-to-entities changeset references object type

After objects get committed to the db, I sometimes want to update a separate index. The simplest version is something like: if(ChangedObject.getType() == typeof(User)) Update(((User) ChangedObject).UserID); The problem is, if it's a related table, then the changed object won't be of the type User, just one of its properties will. ...

Using LINQ and Reflection: How to query for all Classes with [Authorize] Attribute in my Assembly?

Currently, I'm trying to identify which "Controller" classes in my assembly have the [Authorize] attribute associated with them using Reflection and LINQ. const bool allInherited = true; var myAssembly = System.Reflection.Assembly.GetExecutingAssembly(); var controllerList = from type in myAssembly.GetTypes() where ...

how to create a linq query using join and max

I have 2 tables in my linq dbml. One is people with a uniqueid called peopleid and the other is a vertical with a foreign key for peopleid and a uniqueid called id. I need to create a type of linq query that does a left outer join on people and gets the latest record in the vertical table based off the max(id) column. Can anyone sugge...

What is the difference between Equals and = in LINQ?

What is the difference between Equals and = in LINQ? Dim list As List(Of Foo) = (From a As Foo In FooList _ Join b As Bar In BarList _ On a.Something = b.Something _ Select a).ToList() versus Dim list As List(Of Foo) = (From a As Foo In FooList _ Join b As Bar In BarList _ On a.Something Equals b.Something _ Select a).ToList() ...

Accessing empty Linq result is very slow

Getting my feet wet with Linq. I am trying to determine the distinct values contained across four DataColumns. So, I start with var c1types = (from DataRow row in dtSource.Select("hasreq") where row["m"].ToInt() > 0 select new { col = row["m"] }).Distinct(); var c2types = (from DataRow row in dtSource.Sel...

C# + Querying XML with LINQ

Hello, I'm learning to use LINQ. I have seen some videos online that have really impressed me. In an effort to learn LINQ myself, I decided to try to write a query to the NOAA web service. If you put "http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?zipCodeList=20001&format=24+hourly&...

What is the difference between System.Linq and System.Data.Linq?

I was having troubles earlier while trying to declare a ChangeAction parameter in a method, with the IDE saying I might be missing a Namespace. So I right click it and Resolve it and find that System.Data.Linq has been added and now everything is fine. What is the difference between these two namespaces? ...

how to give read only access to the xml file in c#?

how to give read only access to the xml file in c#? ...

LINQ Joining in c# with multiple conditions

Hi Following query is not working is there any problem with it? var possibleSegments = from epl in eventPotentialLegs join sd in segmentDurations on new { epl.ITARequestID, epl.ITASliceNumber, epl.DepartAirportAfter, epl.AirportId_Origin, epl.AirportId_De...

Adding integer value to a list from XML file

I've an Xml file like <SampleFile> <Data> <Element Val="8" /> <Element Val="10" /> <Element Val="12" /> <Element Val="14" /> <Element Val="16" /> <Element Val="9" /> <Element Val="11" /> <Element Val="13" /> <Element Val="15" /> <Element Val="17" /> </Data> </SampleFile> i need to read the att...

Select 5, 10, 15, 20 and so on with LINQ

Hey guys, I want to display items in a dropdownlist like 5%, 10%, 15%, 20% until 100. Is there a way to bind an intelligent LINQ query to the datasource that will do this for me? ...

Need help with formulating LINQ query

I'm building a word anagram program that uses a database which contains one simple table: Words --------------------- varchar(15) alphagram varchar(15) anagram (other fields omitted for brevity) An alphagram is the letters of a word arranged in alphabetical order. For example, the alphagram for OVERFLOW would be EFLOORVW. Every Alphag...

linq in or contains?

How can I use Linq-to-sql to a search like this: where obj.id equals any of the following {1,2,3,4} I would guess I could use the in or perhaps contains? where obj.id in Enumerable.Range( (int) myEnum.Start, (int) myEnum.End) ) ? ...

How do I get a right outer join in L2E?

I have two tables that I set up through the VS Entity Data Model Diagram tool. I'm trying to do a right outer join and it doesn't return results from the 2nd table. I have set up a 0..1 to MANY relationship from the diagram tool. When I run a Linq-To-Entities query, it still defaults to an INNER JOIN. From my understanding of entitie...

Tuples vs. Anonymous Types vs. Expando object. (in regards to LINQ queries)

I am a beginner who finally started understanding anonymous types. (see old post http://stackoverflow.com/questions/3010147/what-is-the-return-type-for-a-anonymous-linq-query-select-what-is-the-best-way-t) So in LINQ queries you form the type of return value you want within the linq query right? It seems the way to do this is anonymou...

Can't use foreach on a anonymous type

I have the code below where I am trying to go through the child questions of my qestAires anonymous type. When I get to the foreach loop i get the error: foreach statement cannot operate on variables of type 'Question' because 'Question' does not contain a public definition for 'GetEnumerator' What do I need to do differentl...

Many-to-many mapping with LINQ

I would like to perform LINQ to SQL mapping in C#, in a many-to-many relationship, but where data is not mandatory. To be clear: I have a news site/blog, and there's a table called Posts. A blog can relate to many categories at once, so there is a table called CategoriesPosts that links with foreign keys with the Posts table and with Cat...

Counting words in a collection using LINQ

I have a StringCollection object with 5 words in them. 3 of them are duplicate words. I am trying to create a LINQ query that will count how many unique words are in the collection and output them to to the console. So, for example, if my StringCollection has 'House', 'Car', 'House','Dog', 'Cat', then it should output like this: House ...