linq

does IQueryable<T> only get returned from the Linq to Sql or Linq to Entities classes?

In the book I'm reading "Pro Linq in C# 2010" (APress, Freeman and Ratz) the author states that IQueryable will only be returned from the classes in the Linq to Sql namespace, not in the general Linq namespace. I was surprised by this, since I thought anything that had a Where on the end had to be IQueryable. Turns out I was wrong, Where...

Linq Join across three tables

I have three tables and need to write a linq query that pulls from all Activities based on two different joins. I need all Activities where the volunteer exist in ActivityVolunteers I need all Activities where the OrganizationID is in the Activity table and the volunteer belongs to the organizaiton (OrganizationVolunteers) but not in...

How to read large XML RAW from Linq to SQL?

I'm pretty new to Linq to SQL & Linq to XML but have cobbled together some code together that put the XML results from a stored proc into an XElement. However, it's started failing, apparently now that the XML data is getting larger (2K+) and my .Parse is reading truncated XML (the XML data comes back in two rows). Before i start fumblin...

Linq List comparing and exclusion

I have two IQueryable<> lists. Say one is filled with objects of Class Bottle and the other is of type Cup. Both classes have a Guid called DrinkID. How would I take my Bottle list and find all the items in the Cup list that have a DrinkID that is NOT in the Bottle list? I am looking for something like this: var bottles = _context.A...

Polymorphic LINQ Query

Hello: Having a bit of a problem getting my LINQ query to return the object type I want to work with. I'm pretty close just need a little bit of input. I have five tables, Objects, People, Locations, Collections, and CollectionEntries. Object is the base class for People, Locations, and Collections. A Collection has many CollectionEnt...

Set linq return property to null

How come setting OrganizationName = null does not work? I am doing a union and would like to set the value to null. from a in Activities select new { a.ActivityID, a.ActivityName, a.OrganizationID, OrganizationName = null } ...

Joining Linq Expressions

I'm working with the new EF4 CTP4 although I don't think this has much to do with that. I am trying to set up a system where I can add auditable fields for our database automatically. What I'm trying to do is combine the following two expressions a => new { a.CreatedBy, a.CreatedTime, a.UpdatedBy, a.UpdatedTime } and...

Is it possible to get other collection than IEnumerable<T> when using LINQ: XML to object?

So I have this huge XML file that I am converting to an object by using LINQ. And currently I am doing: var resultStories = from story in resultXML.Descendants("story") select new NewsStory { ArticleFrequency = from tag in story.Descendants("tag") ...

LIKEs and ORs and stuff in Linq

I'm trying to write a linq-to-sql query using || that behaves the same way as the OR in SQL when combined with a LIKE/Contains. SQL: SELECT * FROM Users WHERE GroupNumber = 'A123456' OR (FirstName like 'Bob%' AND LastName like 'Smith%') This will result in everyone with a name like "Bob Smith" as well as everyone with a GroupNumber e...

Lambda expressions and how to combine them ?

How can I combine two lambda expressions into one using an OR ? I have tried the following but merging them requires me to pass parameters into the Expression.Invoke calls, however I want the value passed into the new lambda to be passed onto each child-lambda.. Expression<Func<int, bool>> func1 = (x) => x > 5; Expression<Func<int, boo...

Difference between Where and Single

Hi All, I'm trying to figure out the difference between Where(Expression) and Single(Expression). Is the Expression passed into single forwarded to a Where function? eg, are these two statements the same? var result = context.Persons.Single(p => p.ID == 5); var result2 = context.Persons.Where(p => p.ID == 5).Single(); ...

Please explain System.Linq.Enumerable.Where(Func<T, int, bool> predicate)

I can't make any sense of the MSDN documentation for this overload of the Where method that accepts a predicate that has two arguments where the int, supposedly, represents the index of the source element, whatever that means (I thought an enumerable was a sequence and you couldn't see further than the next item, much less do any indexin...

How can I iterate through a collection with Foreach to build an XDocument?

The following code gives me the error: The best overloaded method match for 'System.Xml.Linq.XElement.XElement(System.Xml.Linq.XName, object)' has some invalid arguments. What do I have to change so I can iterate through my List<Customer> collection with Foreach building the XDocument? using System; using System.Collections.Ge...

What statements does Linq to entities support?

Does anyone know where I can get a full list of supported statements for linq to entities, this is statements that will be translated and run on the database...? ...

LinQ where clause contains using &&

var yCols = from t in flowPath select new {checkPoint = t["CheckPoint"]}; var test = from x in operations where x["Ops"] = "test" && x["check"].Contains(yCols.Select(y=>y.Variable)) Somehow the contains in where clause part is not right.yCols returns Collection of Checkpoints and if x["Check"] cont...

In Linq to SQL, why does assigning a related entity create a ChangeSet insert ?

Why is the following adding an Insert (of the new Address) to the DataContent ChangeSet, and how can I stop it from doing so? var db = new DataClasses1DataContext(); var a = new Address(); a.StateProvince = db.StateProvinces.First(); Console.WriteLine(db.GetChangeSet().Inserts.Count); ...

Can LINQ order by a column index?

Hi, I'm struggling to find LINQ orderby examples, where data is ordered by a column index. Is this possible to do? Thank you ...

is it ok to use plinq ForAll for a bulk insert into database ?

I'm doing like this: entities.AsParallel().ForAll(o => repository.Insert(o)); is this good, am I going to have more performance with this ? ...

Is Order of items read from a XDocument, by LINQ, Guaranteed?

So what I'm doing is using an xml document to determine the order in which certain SQL scripts need to be ran by a database update. The XML follows this format <ScriptRules> <Database databaseName = “string”> <Folder folderPath = “string” executeAllFiles = boolean> <file order=”first or last”>“Filename”</file> ...

If statements within a Linq where clause

Hello all. Struggling a bit today. I have the following method that returns a list of products..lovely. public static List<tblWeight> GetProductInfo(string memberid, string locationid, string basematerial, string source) { MyEntities getproductinfo = new MyEntities (); return (from p in getproductinfo...