linq

How do I fill a DataSet or a DataTable from a LINQ query resultset ?

How do you expose a LINQ query as an ASMX web service? Usually, from the business tier, I can return a typed DataSet or DataTable which can be serialized for transport over ASMX. How can I do the same for a LINQ query? Is there a way to populate a typed DataSet or DataTable via a LINQ query?: public static MyDataTable CallMySproc() ...

How do I get a distinct, ordered list of names from a DataTable using Linq

Lets say I have a DataTable with a Name column. I want to have a collection of the unique names ordered alphabetically. The following query ignores the order by clause.var names = (from DataRow dr in dataTable.Rows orderby (string)dr["Name"] select (string)dr["Name"]).Distinct(); Why does the orderby not get enfor...

How do you page a collection with LINQ?

How do you page through a collection in LINQ given that you have a startIndex and a count?...

How do I most elegantly express left join with aggregate SQL as LINQ query

SQL: select u.id, u.name, isnull(MAX(h.dateCol), '1900-01-01') dateColWithDefaultfrom universe uleft join history h on u.id=h.id and h.dateCol<GETDATE()-1group by u.Id, u.name...

LINQ on the .NET 2.0 Runtime

Can a LINQ enabled app run on a machine that only has the .NET 2.0 runtime installed? In theory, LINQ is nothing more than syntactic sugar, and the resulting IL code should look the same as it would have in .NET 2.0. How can I write LINQ without using the .NET 3.5 libraries? Will it run on .NET 2.0?...

LinqDataSource - Can you limit the amount of records returned?

I'd like to use a LinqDataSource control on a page and limit the amount of records returned. I know if I use code behind I could do something like this:IEnumerable<int> values = Enumerable.Range(0, 10);IEnumerable<int> take3 = values.Take(3); Does anyone know if something like this is possible with a LinqDataSource control? [Update] I'm ...

How much database performance overhead when using LINQ?

How much database performance overhead is involved with using C# and LINQ compared to custom optimized queries loaded with mostly low-level C, both with a SQL Server 2008 backend? I'm specifically thinking here of a case where you have a fairly data-intensive program and will be doing a data refresh or update at least once per screen an...

C# 3.0 Where extension method with lambda vs LINQtoObjects to filter in memory collections.

I am prototyping some C# 3 collection filters and came across this. I have a collection of products: public class MyProduct { public string Name { get; set; } public Double Price { get; set; } public string Description { get; set; } } var MyProducts = new List<MyProduct> { new MyProduc...

Linq to objects - select first object

I know almost nothing about linq. I'm doing this: var apps = from app in Process.GetProcesses() where app.ProcessName.Contains( "MyAppName" ) && app.MainWindowHandle != IntPtr.Zero select app; Which gets me all the running processes which match that criteria. But I don't know how to get the first one. The examples I can find...

Querying like Linq when you don't have Linq.

I have a project that I'm currently working on but it currently only supports the .net framework 2.0. I love linq, but because of the framework version I can't use it. What I want isn't so much the ORM side of things, but the "queryability" (is that even a word?) of Linq. So far the closest is llblgen but if there was something even li...

Beginners Guide to LINQ

During the beta of Stack Overflow, I have seen quite a few questions about LINQ SQL but know nothing about it... it sounds very interesting. What is LINQ and how do I get started? Links guides or documentation a bonus :) PS: I am a long time C# developer who daily uses Datatables and Parameterized SQL ...

Has anyone run performance benchmarks comparing LINQ

to yesteryear's standards such as nHibernate, good old custom ORM, or something like LLBGenPro? Also, having run the benchmarks, what are your suggestions? ...

Import Namespace System.Query

I am trying to load Linq on my .Net 3.5 enabled web server by adding the following to my .aspx page: <%@ Import Namespace="System.Query" %> However, this fails and tells me it cannot find the namespace. The type or namespace name 'Query' does not exist in the namespace 'System' I have also tried with no luck: System.Data.Linq...

How to return a page of results from SQL?

Many applications have grids that display data from a database table one page at a time. Many of them also let the user pick the number of records per page, sort by any column, and navigate back and forth through the results. What's a good algorithm to implement this pattern without bringing the entire table to the client and then filte...

Expression.Invoke in Entity Framework?

The Entity Framework does not support the Expression.Invoke operator (You receive the following exception when trying to use it: "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities.) Has anyone got a workaround for this missing functionality? I would like to use the PredicateBuilder detailed here in an Entity Fr...

LINQ query on a DataTable

I'm trying to perform a LINQ query on a DataTable object and bizarrely I am finding that performing such queries on DataTables is not straightforward. For example: var results = from myRow in myDataTable where results.Field("RowNo") == 1 select results; This is not allowed. Any ideas how to get something like this working? I'm amazed ...

Conditional Linq Queries

We're working on a Log Viewer. The use will have the option to filter by user, severity, etc. In the Sql days I'd add to the query string, but I want to do it with Linq. How can I conditionally add where-clauses? ...

How can I remove nodes from a SiteMapNodeCollection?

I've got a Repeater that lists all the web.sitemap child pages on an ASP.NET page. Its DataSource is a SiteMapNodeCollection. But, I don't want my registration form page to show up there. Dim Children As SiteMapNodeCollection = SiteMap.CurrentNode.ChildNodes 'remove registration page from collection For Each n As SiteMapNode In SiteM...

LINQ, entity that implements Interface and exception in mapping

I'm using repository pattern with LINQ, have IRepository.DeleteOnSubmit(T Entity). It works fine, but when my entity class has interface, like this: public interface IEntity { int ID {get;set;} } public partial class MyEntity: IEntity { public int ID { get { return this.IDfield; } set { this.IDfield=value; } ...

LINQ-to-SQL vs stored procedures?

I took a look at the "Beginner's Guide to LINQ" post here on StackOverflow (http://stackoverflow.com/questions/8050/beginners-guide-to-linq), but had a follow-up question: We're about to ramp up a new project where nearly all of our database op's will be fairly simple data retrievals (there's another segment of the project which already...