linq

Linq Query ignore empty parameters

How do I get Linq to ignore any parameters that are empty? So Lastname, Firstname, etc? If I have data in all parameters it works fine... refinedresult = From x In theresult _ Where x.<thelastname>.Value.TestPhoneElement(LastName) And _ x.<thefirstname>.Value.TestPhoneElement(FirstName) And _ ...

msbuild for .NET 3.5 issue with csla and System.Linq

This is a weird problem. I am trying to build a .NET 3.5 solution with msbuild. I generally write custom build scripts for this, and when I tried this time to build a simple .NET assembly which internally uses CSLA, it started giving me Linq errors. However, if I build the proj file via msbuild (command line), it seems to build just fi...

Linq and WPF databinding with an association database

I have 5 tables in my database with the following fields: Customer: ID (int), Name (string) Project: ID (int), Name (string) Task: ID (int), Name(string) Customer_Project: ID (int), CustomerID (int) ProjectID (int) Project_Task: ID (int), ProjectID(int), TaskID(int) The last two tables create associations so any number of Customers...

Find Elements by Attribute using XDocument

This query seems to be valid, but I have 0 results. IEnumerable<XElement> users = (from el in XMLDoc.Elements("Users") where (string)el.Attribute("GUID") == userGUID.ToString() select el); My XML is as follows: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Users> <User GUID="68327fe2...

What is the big deal with IQueryable?

I've seen a lot of people talking about IQueryable and I haven't quite picked up on what all the buzz is about. I always work with generic List's and find they are very rich in the way you can "query" them and work with them, even run LINQ queries against them. So I'm wondering if there is a good reason to start considering a differen...

Use LINQ to query nested OData collection

I'm playing around with the new Netflix OData feed (http://odata.netflix.com/Catalog/) and having some issues. I'm trying to learn LINQ at the same time but having difficulty doing what I thought was going to be quite simple. I'd like to return a list of Titles that match a given Genre. The Titles object contains a collection of Genre...

LINQ Nested Where

If I have the following model; public List<RecommendedProduct> recommendations Then public class RecommendedProduct public List<Product> Products Then the Product; public class Product public string Code The recommendations list has, as an example, 10 items in it. Each recommendations item has two Products in it. How, wi...

.Net - Join together all item of a list in a output string

How can I write a Linq expression (or anything else) that select item from a List and join them together ? Example IList<string> data = new List<string>(); data.Add("MyData1"); data.Add("MyData2"); string result = //some linq query... I try data.Select(x => x + ","); //result = "MyData1, MyData2" ...

LINQ Next Item in List

Taking a look at my question HERE, I now want to return the next recommendation object (after) the one that matches the criteria. So say I found item 6 out of 10, I'd like the query to return item 7 instead. Or is there a better way? ...

How would you write this C# code (that uses the yield keyword) succinctly in Ruby?

Is there a good way to emulate yield in Ruby? I'm interested in writing similar 'infinite fib sequence' in Ruby. Here is the code: using System; using System.Collections.Generic; using System.Linq; namespace cs2 { class Program { static void Main(string[] args) { var i=Fibs().TakeWhile(x=>x < 1000).Whe...

.DBML file and LINQ to SQL

In my DBML file I have mapped some tables and stored procedures, and the stored procedures return type is ISingleResult . T is some mapped table. But I want to take the data into my own created entities rather than LINQ to SQL created entites. The entites created by me are also the same as the mapped table entities and their use lies whe...

how to Update the XMl value and write back using LINQ

I have a query about updating a node value using Linq, For example I have to update <Student> <studentdetail> <studentname>test</studentname> <libraryid>hem001</libraryid> </studentdetail> </Student> In the above XML I want to change the value of Student name "test" to something else like "Undertest". ...

Remove XML Tag using linq c#

I am having on xml from which i have to remove the one book detail <Books> <bookdetail> <bookname>ThreeIdiot</bookname> <bookauthor>chetan bhagat</bookauthor> <bookid>idi001</bookid> <isavailable>true</isavailable> <subscribername>NA</subscribername> </bookdetail> <bookdetail> <bookname>Csharp</bookname> ...

time calculation within LINQ

Hi I want a linq query to return a calculated timespan, i have used the timespan function before, but im not sure how to incorporate it into linq. Basically the linq is returning a datetime field which i want to subtract from the current datetime to get days and hours. Any help appreciated! Thanks ...

Concatenate int and string in LINQ

HI, I am using the following code from c in Country where c.IsActive.Equals(true) orderby c.CountryName select new { countryIDCode = c.CountryID + "|" + c.TwoDigitCode, countryName = c.CountryName } but following is the error while doing this... Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to En...

Converting F# Quotations into LINQ Expressions

Hi, I can convert a quotation of type Expr<'a -> 'b> to a Linq expression via the following snippet: /// Converts a F# Expression to a LINQ Lambda let toLambda (exp:Expr) = let linq = exp.ToLinqExpression() :?> MethodCallExpression linq.Arguments.[0] :?> LambdaExpression /// Converts a Lambda quotation into a Linq Lamba Expres...

Combining linq queries with "group by"

I wrote two queries to find duplicates in the array var groups = from item in array group item by item; var q1 = from grp in groups where grp.Count() > 1 select grp.Key; Is there a way to write this in one LINQ query? I know I can use method calls array.GroupBy(i => i).Where(g => g.Coun...

What is the difference between these two LINQ statements?

I had the 1nd statement in my code and found it not giving an accurate count, it was returning 1 when the correct answer is 18. To try and debug the problem I broke it out creating the 2nd statement here and the count returns 18. I just don't see what the difference is between these two. It seems like the 1st is just more compact. I'm c...

A linq join combined with a regex

Is it possible to combine these 2 queries or would this make my code too complex? Also I think there should be a performance gain by combining these queries since I think in the near future my source table could be over 11000 records. This is what i came up with so far : Dim lit As LiteralControl ' check characters not in alphabet Dim...

How to convert a number to a range of prices

I want to calculate the amount to charge my customers, when they buy licenses of my product. I sell it in ranges of licenses: 1-10 : $50/user 11-20 : $40/user 21-30 : $30/user 31-50 : $20/user So when someone purchases 136 licenses, I will charge him: 50 x 2 x $20 = $2000 30 x 1 x $30 = $900 6 x $50 = $300 I'm looking for an...