linq

What's the difference between IQueryable and IEnumerable

I'm confused as to the difference. Being fairly new to .Net, I know I can query IEnumerables using the Linq extensions. So what is this IQueryable and how does it differ? ...

How can I stop an auto-generated Linq to SQL class from loading ALL data?

DUPLICATE of http://stackoverflow.com/questions/2433422/how-can-i-stop-an-auto-generated-linq-to-sql-class-from-loading-all-data post answers there! I have an ASP.NET MVC project, much like the NerdDinner tutorial example. (I'm using MVC 2, but followed the NerdDinner tutorial in order to create it). As per the instructions in part 3...

How can I stop an auto-generated Linq to SQL class from loading ALL data?

UPDATE: from what I'm hearing, I was imagining the problem I describe below. So, this is pretty much a non-question. Future readers, move on... nothing to see here. I have an ASP.NET MVC project, much like the NerdDinner tutorial example. (I'm using MVC 2, but followed the NerdDinner tutorial in order to create it). As per the instru...

create a dictionary using 2 lists using LINQ

I am trying to create a dictionary from 2 lists where one list contains keys and one list contains values. I can do it using for loop but I am trying to find if there is a way of doing it using LINQ. Sample code will be helpfull. Thanks!!!! ...

LINQ-to-SQL IN/Contains() for Nullable<T>

I want to generate this SQL statement in LINQ: select * from Foo where Value in ( 1, 2, 3 ) The tricky bit seems to be that Value is a column that allows nulls. The equivalent LINQ code would seem to be: IEnumerable<Foo> foos = MyDataContext.Foos; IEnumerable<int> values = GetMyValues(); var myFoos = from foo in foos wh...

OrderBy and Distinct using LINQ-to-Entities

Here is my LINQ query: (from o in entities.MyTable orderby o.MyColumn select o.MyColumn).Distinct(); Here is the result: {"a", "c", "b", "d"} Here is the generated SQL: SELECT [Distinct1].[MyColumn] AS [MyColumn] FROM ( SELECT DISTINCT [Extent1].[MyColumn] AS [MyColumn] FROM [dbo].[MyTable] AS [Extent1] ) AS [Distinct1]...

Problem with LINQ to XML and Namespaces

I am having problems with working with a third party XML string that contains a Namespace with LINQ to XML. In the below code everything works find. I am able to select the xElement (xEl1) and update its value. 'Example Without Namespace Dim XmlWithOutNs = _ <?xml version="1.0"?> <RATABASECALC> <RATEREQUEST> ...

Any Way to Use a Join in a Lambda Where() on a Table<>?

I'm in my first couple of days using Linq in C#, and I'm curious to know if there is a more concise way of writing the following. MyEntities db = new MyEntities(ConnString); var q = from a in db.TableA join b in db.TableB on a.SomeFieldID equals b.SomeFieldID where (a.UserID == CurrentUser && b.MyField ...

Linq To SQL - Specified cast is not valid - SingleOrDefault()

I am trying to do the following... Request request = ( from r in db.Requests where r.Status == "Processing" && r.Locked == false select r ).SingleOrDefault(); It is throwing the following exception... Message: Specified cast is not valid. StackTrace: at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression qu...

Is an object still connected to a list after FirstOrDefault?

Here's my code: Event thisEvent = (from i in list where (i.eventID == eventID) select i).FirstOrDefault(); if (thisEvent != null) { thisEvent.eventResolved = resolved; thisEvent.eventSequence.Add(item); } "list" is a collectio...

Dynamic query to immediate execute?

I am using the MSDN Dynamic linq to sql package. It allows using strings for queries. But, the returned type is an IQueryable and not an IQueryable<T>. I do not have the ToList() method. How can I this immediate execute without manually enumerating over the IQueryable? My goal is to databind to the Selecting event on a linqtosql datas...

Where is a good place to start learning LINQ

Where is a good place to start learning LINQ for .net, and what are the resources i should use to put the knowledge into practice? ...

How to get records from subquery using union in linq

sql = " SELECT * FROM userDetail "; sql += " WHERE userId IN "; sql += " (SELECT friendId FROM userFriends "; sql += " WHERE approvalStatus='True' AND userId=" + userId; sql += " UNION"; sql += " SELECT userId FROM userFriends "; sql += " WHERE approvalStatus='True' AND friendId=" + userId + ")"; ...

Is LINQ to Dataset subset of LINQ to EF or these two are independent?

Is LINQ to Dataset subset of LINQ to EF or these two are independent? ...

C# - LINQ Statements with OR clauses

Hello, I am trying to use LINQ to return a list of tasks that are in one of three states. These states are: 10 - Completed 11 - Incomplete 12 - Skipped The state is available through a property called "TaskStateID". I can do this in LINQ with just one state as shown here: var filteredTasks = from task in tasks sel...

Using conditionals in Linq Programatically

I was just reading a recent question on using conditionals in Linq and it reminded me of an issue I have not been able to resolve. When building Linq to SQL queries programatically how can this be done when the number of conditionals is not known until runtime? For instance in the code below the first clause creates an IQueryable that, ...

A problem with compare item value

Hi, I have defined my class: public class Host { public string Name; } then a strongly-typed dictionary: Dictionary<string, Host> HostsTable; then I try to compare a value: if (HostsTable.Values.Where(s => s.Name == "myhostname") != null) { doSomething } and the problem is, nothing is found, even I'm sure the item is on t...

Help Understanding Enumerable.Join Method

Yesterday I posted this question regarding using lambdas inside of a Join() method to check if 2 conditions exist across 2 entities. I received an answer on the question, which worked perfectly. I thought after reading the MSDN article on the Enumerable.Join() method, I'd understand exactly what was happening, but I don't. Could someone ...

Updating multiple tables at the same time in Linq-to-SQL

How do I update two tables at the same time using Linq-to-SQL? var z = from a in db.Products join b in db.ProductSubcategories on a.ProductSubcategoryID equals b.ProductSubcategoryID join d in db.ProductCategories on b.ProductCategoryID equals d.ProductCategory...

Merging sequences by type With LINQ

I want to use LINQ to convert this IEnumerable<int>[] value1ByType = new IEnumerable<int>[3]; value1ByType[0]= new [] { 0}; value1ByType[1]= new [] {10,11}; value1ByType[2]= new [] {20}; var value2ToType = new Dictionary<int,int> { {100,0}, {101,1}, {102,2}, {103,1}}; to this var value2ToValue1 = new Dictionary<int,int> { {100, 0},...