linq

When does a lambda in an extension method do too much?

I realize this is partially subjective, but I'm generally curious as to community opinion and have not been able to successfully find an existing question that tackles this issue. I am in a somewhat religious debate with a fellow coworker about a particular Select statement in a L2EF query. .Select(r => { r.foo.Bar = r.bar; r.f...

How to check if a control is child of another control? "Control.IsChildOf"

I have 3 panels: <asp:Panel ID="ParentPanel" runat="server"> <asp:Panel ID="AnnoyingPanel" runat="server"> <asp:Panel ID="P" runat="server"> </asp:Panel> </asp:Panel> </asp:Panel> How can I check if P is child of ParentPanel? Is there some LINQish way to do it? Is there some more optimized way than the one I p...

Using LINQ, how do I find an object with a given property value from a List?

I have a class called Questions. This Questions has properties QuestionID and QuestionAnswer. While iterating through this List of Question in foreach, I have to find .QuestionID = 12. If I find .QuestionID = 12 then I have to immediately assign a value to .QuestionAnswer = "SomeText" of .QuestionID = 14. I don't want iterate again in...

First try wcf data service always times out from client

I have read all other posts and have been googling this for the last 2 hours! I started WCF Data Services about 3 hours ago btw. My service is on an asp.net4 app, the ado entity model exposes an sql server db. Here is FasDataService.svc.cs public class FasDataService : DataService<FASStoreEntities> { public static void InitializeSe...

Linq - What is the quickest way to find out deferred execution or not?

What is the quickest way to find out which .net framework linq methods (e.g .IEnumerable linq methods) are implemented using deferred execution vs. which are not implemented using deferred execution. While coding many times, I wonder if this one will be executed right way. The only way to find out is go to MSDN documentation to make su...

How is LINQ compiled into the CIL?

For example: var query = from c in db.Cars select c; foreach(Car aCar in query) { Console.WriteLine(aCar.Name); } How would this translate once it is compiled? What happens behind the scenes? ...

Linq query question: Distinct based on object's property

I am aggregating multiple List's into one List and would like to make it distinct based on one of the properties of Foo (Foo.Prop1).. I do not have access to modify Foo's Equality comparer. Dictionary<string, List<Foo>> fooDictionary = new Dictionary<string, List<Foo>>(); List<Foo> foovals = (from e in fooDictionary ...

"Server failed to resume the transaction" error in SQL Server 2008 + .NET3.5 + LINQ

The aspx.cs Code: the code itself is pretty big, and the code here is fictional, but it looks (the important part) like this: foreach (Transaction trans in vTransactionList) { switch (trans) { case 201: codehere; break; case 202: codehere; break; case 203: ...

Linq conditional query in C#

I have the following two database tables. A group contains multiple members. Groups: Id (int) | Name (int) Members: Id (int) | GroupId (int) | IsExpert (bit) I need to write a linq to sql query that returns the Groups that has no experts. Need some help ...

C# Determing whether any element in a string array contains a given string anywhere

I have a string array: string[] Animals = {"Cat", "Dog", "Fish"}; I then want to determine which element contains the sequence "is" and return that entire element; in this case "fish" If I want to find "gh", it does not exist in the list, so it should return the first element, in this case "Cat" I've tried this linq code, but i don'...

Adding a search to a linq query.

I have a basic datatable, it can be completely generic for this example, except for that it contains a Username column. I'd like to have a simple textbox and a button that performs a similarity search on the Username field. I know I can use the .Contains() method and it will translate to LIKE in sql, but is this the correct way of doin...

Method Name(int, DateTime) has no supported translation to SQL.

I have a function, Name(int, DateTime), that I'd like to use in a linq2sql query. Its a simple function that computes the difference between the passed in DateTime object and DateTime.Now using a TimeSpan. I then do some basic math stuff with .TotalHours and the passed in int. The most complicated function is Math.Pow(double,double)....

LINQ to Objects at Runtime from Text

Is there any library or custom control that allows to construct LINQ to Objects (IEnumerable collection) queries at run-time from text, it would be nice to have IntelliSense support, like it is in Visual Studio code editor. I need to code CustomControl similar to http://xte.codeplex.com/ with IntelliSense and some other features that wi...

Create a new XMLDocument by filtering an existing document in c# using xpath

Hi I have a situation where I receive an XML (document) file from an external company. I need to filter the document to remove all data I am not interested in. The file is about 500KB but will be requested very often. let say the following file: <dvdlist> <dvd> <title>title 1</title> <director>directory 2</director> <p...

linq object equality and how to properly override it

Hi, Why is var excludes = users.Except(matches); not excluding the matches? What is the proper way if I want the equality comparer to use only the ID? Examples would be appreciated. public class User { public int ID { get; set; } public string Name { get; set; } public override string ToString() { return ID.T...

Simplifying overly complicated LINQ query - queries

public partial class MembershipModule : BaseEntity<MembershipModule> { /// <summary> /// Returns wheter a module is accessible /// </summary> public static bool IsAccessible(MembershipModule module) { // In absence of a module, no security applies to the page if(module == null) return true;...

Having problems with this Linq/Lambda statement :(

Hi folks, Update - I fixed the query below. I had the wrong query/error statement :( I have the following statement: var posts = BlogPostRepository.Find() .Where(x => x.Tags.Where(y => y.Name == tag)) .ToList(); It's giving me a compile time error with the 2nd (inner) Where clause, saying :- Error 1 Cannot convert...

Linq/SQL Query Sorting for Multiple LIKE conditions

I have a table in a db that has a structure like this: Date { ID, Username, Label, DateTime } I want to be able to perform a basic .Contains search in linq on the Username and Label columns, but there's a catch. I'd like to order by the number of LIKE matches. Here is what I mean by this: If I have an instance of Da...

Performing a Contains within an Intersect

I have a fairly complicated linq query that returns an item and a string[] of one column in the item's many-to-many relationship. So I return an anonymous type sort of like this: var q = from k in db.Items join m in db.ManyRel on k.Id equals m.ItemID select new { k, list = (from t in m ...

Linq, using ToLookup to project values to different named variables

var tmpProjection = myCollection.ToLookup(t => t.SomeBoolValue); var listOneFinal = tmpProjection[true]; var listTwo = tmpProjection[false]; First question, is there a way to assign it to listOne and listTwo in some shorter way, I know I'm being pedantic here, ... just asking. Now, var listThree = listTwo.ToLookup(t => t.SomeOtherBoo...