linq

c# bind 2 lists to repeater

Hi [c# linq] i have 2 datasources, 1 coming from an xml document and 1 coming from an sql server database, both return an IEnumerable<EventsDetails> is it possible to bind both of these lists to a single repeater? ...

Convert custom datatable sort to LINQ or lambda expressions

I have a custom sort routine that works great, but I was curious about how I would convert it to use less code with LINQ or lambda. SortByGrade sorts a string value representing a grade ( K - 12 ) so that it returns: K, 1, 2, 3, 4, etc. instead of 1, 10, 2, etc /// <summary> /// Sorts a grade ( K - 12 ) numerically /// </su...

SQL to select rows that match a URL with wildcard

I have a table in the db with one column containing a URL like http://site.com/users/*/profile I am given a URL (like http://site.com/users/234/profile) and want to select all the rows in the db that match the url (in this case * is a wildcard). I was thinking of using Regex to do this, by replacing the * with regex for any character....

Why doesn't XElement have a GetAttributeValue method?

Sometimes I'd like to know the reasoning of certain API changes. Since google hasn't helped me with this question, maybe stackoverflow can. Why did Microsoft choose to remove the GetAttribute helper method on xml elements? In the System.Xml world there was XmlElement.GetAttribute("x") like getAttribute in MSXML before it, both of which r...

LINQ to SQL Default Value ?? nullable

Hi Problem: How to get Linq to make a default value of 'noImage.jpg' if null is returned from the database. I'm querying a single table: <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="Materials.MaterialsDataClassesDataContext" TableName="Materials" EnableDelete="True" EnableInsert="True" EnableUpdate=...

LINQ to SQL Finding objects not listed in another list

I am programming a data entry application for a vet and I've followed many of the principles used in the MVC Nerd Diner application. I'm 90% finished with my app, but trying to clean up an annoying issue: Currently when a user adds a pet to an invoice, I have a dropdown that lists all the customers current pets - whether or not they ar...

Linq - get top 2 records through criteria

Hi folks, i have data in following format: colA colB 2010 10 2010 20 2010 30 1999 99 I need to obtain output as follows using Linq/Lambda expression: colA colB 2010 10 1999 99 colB could be any non-99 value but t...

How to do Linq on ITypedList?

So far, I find Linq can be used on existing fields and properties of a class, not on virtual properties. In other words, ITypedList can not work with Linq, even by dynamic Linq. I tried the following code: IQueryable contact ; ... dynamic l = contact.Select("Customer.Name as Name"); // Customer is a virtual property provid...

how to create dynamic Aspxmenu from database

*I work on C#.*I want to develop asp.net application which contains menu but menu items should be generated from database. My intension is that Administrator can change menu items by working only on database, no need to change front end any how. ** For example: Web page contains Menu as 1. Home 2. About Us 3. Contact Us ** ...

LINQ extension method help sought

Hi all, this is by far my toughest question yet and I'm hoping someone has stumbled upon this issue before and found an elegant answer. Basically, I've got a few linq extension methods (which just happen to be in subsonic but would be applicable in any linq derivative) that are working perfectly (extensions for .WhereIn() and .WhereNotI...

Will indexing a SQL table improve the performance of a LINQ statement?

Apologies for what may very well be a stupid question. I'm just intrigued as to (a) will indexing improve performance (b) how will it improve performance and (c) why will it improve performance? Also, if this does improve performance, would this be the case across the board for LINQ to SQL, LINQ to Entities, LINQ to Objects, etc, etc. ...

C#: Adding data to dictionary

I have a list like List<string> TempList = new List<string> { "[66,X,X]", "[67,X,2]", "[x,x,x]" }; I need to add data to the dictionary from the above list Dictionary<int, int> Dict = new Dictionary<int, int>(); so the Dict should contain Key --> 66 value --> 67 i need to take 66(first value) from first string([66,X,X]) and 67(f...

"where in " clause in linq

below is my sql query select * from test1View where test1ID in (select distinct(test2ID) from test2Result) I want this query in Linq please ...

Using GroupBy, Count and Sum in LINQ Lambda Expressions

I have a collection of boxes with the properties weight, volume and owner. I want to use LINQ to get a summarized list (by owner) of the box information e.g. **Owner, Boxes, Total Weight, Total Volume** Jim, 5, 1430.00, 3.65 George, 2, 37.50, 1.22 Can someone show me how to do this with Lambda expression...

IEnumerable to string

Hi. I have a DataTable that returns IDs ,1 ,2 ,3 ,4 ,5 ,100 ,101 I want to convert this to single string value, i.e: ,1,2,3,4,5,100,101 How can i rewrite the following to get a single string var _values = _tbl.AsEnumerable().Select(x => x); ...

How to dynamically group a list depending on role in asp.net mvc.

Here is my scenario: We would like to have a page listing donors, depending on the user viewing the page we would like to group by the donor's giving level, or just their sort name. The twist that is throwing me is that we would like to group the Anonomous Donors and give a count based on the grouping. In my controller I have [Http...

Linq to SQL Chunked Delete or Update Operation?

I have a lot of rows to delete in a table, and using ADO.NET I might send a SqlCommand with this text: WHILE(1=1) BEGIN DELETE TOP(5000) FROM myTable WHERE myval=123 IF @@ROWCOUNT < 5000 BREAK END I would wrap that in a transaction or 2 and could then delete in chunks so the DB could come up for air. I would like to do th...

LINQ update value in parent rows from ther child rows.

Hello! I use linq2sql and m_DateContext.Dates class for table ID | ParentID | Datestamp ---|----------|---------- 1 | NULL | 1.8.2010 ---|----------|---------- 2 | 1 | 2.8.2010 ---|----------|---------- 3 | 1 | 4.8.2010 etc... I need to write the linq query to select only rows where ParentID is NULL (ex: ID=1),...

How make LINQ query with GroupBy and LEFT JOIN

I'm using EF4 and i need to make this query with LINQ but i don't know how. If i have 3 tables: ProductType Product Season ProductType -> one-to-many -> Product -> many-to-one -> Season i would like to have a list of all the ProductType with their Products for one Season. Please note that i need to list ALL the ProductType even if ...

Outer Variable Trap

What exactly is the Outer Variable Trap? Explanation and examples in C# are appreciated. EDIT: Incorporating Jon Skeet's diktat :) Eric Lippert on the Outer Variable Trap ...