linq

LINQ FormatException

I currently have an existing database and I am using the LINQtoSQL generator tool to create the classes for me. The tool is working fine for this database and there are no errors with that tool. When I run a LINQ to SQL query against the data, there is a row that has some invalid data somehow within the table and it is throwing a System....

Crystal Reports and LINQ

Has anyone figured out how to use Crystal Reports with Linq to SQL? ...

Wrap a delegate in an IEqualityComparer

Several Linq.Enumerable functions take an IEqualityComparer<T>. Is there a convenient wrapper class that adapts a delegate(T,T)=>bool to implement IEqualityComparer<T>? It's easy enough to write one (if your ignore problems with defining a correct hashcode), but I'd like to know if there is an out-of-the-box solution. Specifically, I wa...

.NET List<T> Concat vs AddRange

What is the difference between the AddRange and Concat functions on a generic List? Is one recommended over the other? ...

How do you cast an IEnumerable<t> or IQueryable<t> to an EntitySet<t> ?

In this situation I am trying to perform a data import from an XML file to a database using LINQ to XML and LINQ to SQL. Here's my LINQ data model: public struct Page { public string Name; public char Status; public EntitySet<PageContent> PageContents; } public struct PageContent { public string Content; public str...

Requiring users to update .NET

I'm working on some production software, using C# on the .NET framework. I really would like to be able to use LINQ on the project. I believe it requires .NET version 3.5 (correct me if I'm wrong). This application is a commercial software app, required to run on a client's work PC. Is it reasonable to assume they have .NET 3.5, or assum...

linq equivalent of 'select *' sql for generic function?

I've got a generic<> function that takes a linq query ('items') and enumerates through it adding additional properties. How can I select all the properties of the original 'item' rather than the item itself (as the code below does)? So equivalent to the sql: select *, 'bar' as Foo from items foreach (var item in items) { var newIte...

LINQ to entities - Building where clauses to test collections within a many to many relationship.

So, I am using the Linq entity framework. I have to entities "Content" and "Tag" They are in a many-to-many relationship with one another. Content can have many tags and Tags can have many Contents. So I am trying to write a query to select all contents where any tags names are equal to "blah." The entities both have a collection of the...

Can I return the 'id' field after a LINQ insert?

When I enter an object into the DB with Linq-to-SQL can I get the id that I just inserted without making another db call? I am assuming this is pretty easy, I just don't know how. Thank you. ...

Dynamic LINQ and Dynamic Lambda expressions?

What is the best way of dynamically writing LINQ queries and Lambda expressions? I am thinking of applications where the end user can design business logic rules, which then must be executed. I am sorry if this is a newbie question, but it would be great to get best practices out of experience. ...

Design Patterns using IQueryable<T>

With the introduction of .NET 3.5 and the IQueryable<T> interface, new patterns will emerge. While I have seen a number of implementations of the Specification pattern, I have not seen many other patterns using this technology. Rob Conery's Storefront application is another concrete example using IQueryable<T> which may lead to some new ...

How fast is LINQ?

I need to manipulate 100,000 - 200,000 records. I am thinking of using LINQ (to SQL) to do this. I know from experience that filtering dataviews is very slow. So how quick is LINQ? Can you please tell me your experiences and if it is worth using, or would I be better off using SQL stored procedures (heavy going and less flexible)? Wit...

Linq to SQL Grouping Child Relationships

I'm trying to run a LINQ to SQL query that returns a result in a grid view in a search engine style listing. In the simplified example below, is it possible to populate the collection with a comma-separated list of any children that the parent has (NAMESOFCHILDREN) in a single query? var family = from p in db.Parents whe...

Getting started using Linq, what do I need?

Basically what the title says. (Forgive me because I am a .NET newb) In my department, we have a server running .net 3.5 and ever since I got into this section I have been using LINQ. However, I am starting a personal project on a different server (obviously), so 2 questions: What do I need to get up and running with LINQ? What doe...

Can you do LINQ-like queries in a language like Python or Boo?

Take this simple C# LINQ query, and imagine that 'db.Numbers' is an SQL table with one column, Number: var result = from n in db.Numbers where n.Number < 5 select n.Number; This will run very efficiently in C#, because it generates an SQL query something like "select Number from Numbers where Number < 5". What it ...

How do I write this in Ruby/Python? Or, can you translate my LINQ to Ruby/Python?

Yesterday, I asked this question and never really got an answer I was really happy with. I really would like to know how to generate a list of N unique random numbers using a functional language such as Ruby without having to be extremely imperative in style. Since I didn't see anything I really liked, I've written the solution I was lo...

What is the LINQ way to implode/join a string array?

I have the following string array: var sa = new string[] {"yabba","dabba","doo"}; I can convert it to "yabba, dabba, doo" it using string.Join() but what is the super-cool LINQ way of doing it? The Join extension method seems promising but for a novice like me very confusing. ...

How do I avoid a memory leak with LINQ-To-SQL?

I have been having some issues with LINQ-To-SQL around memory usage. I'm using it in a Windows Service to do some processing, and I'm looping through a large amount of data that I'm pulling back from the context. Yes - I know I could do this with a stored procedure but there are reasons why that would be a less than ideal solution. An...

LINQ to XML Newbie Question

Greetings! I'm working on wrapping my head around LINQ. If I had some XML such as this loaded into an XDocument object: <Root> <GroupA> <Item attrib1="aaa" attrib2="000" /> </GroupA> <GroupB> <Item attrib1="bbb" attrib2="111" /> <Item attrib1="ccc" attrib2="222" /> <Item attrib1="ddd" attrib...

Generic LINQ query predicate?

Not sure if this is possible or if I'm expressing correctly what I'm looking for, but I have the following piece of code in my library repeatedly and would like to practice some DRY. I have set of SQL Server tables that I'm querying based on a simple user-supplied search field ala Google. I'm using LINQ to compose the final query based ...