linq

Aging Data Structure in C#

I want a data structure that will allow querying how many items in last X minutes. An item may just be a simple identifier or a more complex data structure, preferably the timestamp of the item will be in the item, rather than stored outside (as a hash or similar, wouldn't want to have problems with multiple items having same timestamp)....

SQL Server 2008 vs 2005 Linq integration

Linq To SQL or Entity framework both integrate nicely with SQL Server 2005. The SQL Server 2008 spec sheet promises even better integration - but I can't see it. What are some examples of what you can do Linq-wise when talking to a 2008 server that you can't when talking to SQL Server 2005? ...

LINQ to SQL Mapping From Money to Double

I'm working with LINQ for the first time and wanted to get the Mapping to work when I have a money type in SQL, but my domain object property is of type double. How can I express this in the XML file, or in code so that the mapping does not throw the usual "invalid cast" exception? ...

Learning about LINQ

Overview One of the things I've asked a lot about on this site is LINQ. The questions I've asked have been wide and varied and often don't have much context behind them. So in an attempt to consolidate the knowledge I've acquired on Linq I'm posting this question with a view to maintaining and updating it with additional information as ...

How to find an implementation of a C# interface in the current assembly with a specific name?

I have an Interface called IStep that can do some computation (See "Execution in the Kingdom of Nouns"). At runtime, I want to select the appropriate implementation by class name. // use like this: IStep step = GetStep(sName); ...

How do I use Linq for paging a generic collection?

I've got a System.Generic.Collections.List(Of MyCustomClass) type object. Given integer varaibles pagesize and pagenumber, how can I query only any single page of MyCustomClass objects? ...

Am I missing something about LINQ?

I seem to be missing something about LINQ. To me, it looks like it's taking some of the elements of SQL that I like the least and moving them into the C# language and using them for other things. I mean, I could see the benefit of using SQL-like statements on things other than databases. But if I wanted to write SQL, well, why not jus...

Mocking and IQueriable<T>

Hello. I've ran into a problem while trying to test following IRepository based on NHibernate: public class NHibernateRepository<T>: Disposable, IRepository<T> where T : IdentifiableObject { ... public IQueryable<T> Query() { return NHibernateSession.Linq<T>(); } } How on the Hell to mock returning IQueryable out in the way ...

IntelliSense for XElement objects with XML schema

Reading an article called "Increase LINQ Query Performance" in Jully's MSDN magazine, the author states that using an Imports in VB providing a path to schema in the current project will turn IntelliSense on for XElement. In the code provided, he uses statements like xelement.@name to retreive attributes values, and so on. I did not try...

NHibernate vs LINQ to SQL

As someone who hasn't used either technology on real-world projects I wonder if anyone knows how these two complement each other and how much their functionalities overlap? ...

Total row count in Gridview using LinqDataSource and paging

Hello, I'm having a problem obtaining the total row count for items displayed in a Gridview using Paging and with a LinqDataSource as the source of data. I've tried several approaches: protected void GridDataSource_Selected(object sender, LinqDataSourceStatusEventArgs e) { totalLabel.Text = e.TotalRowCount.ToString(); } re...

The best way to get a count of IEnumerable<T>

Whats the best/easiest way to obtain a count of items within an IEnumerable collection without enumerating over all of the items in the collection? Possible with LINQ or Lambda? ...

Coolest C# LINQ/Lambdas trick you've ever pulled?

Saw a post about hidden features in C# but not a lot of people have written linq/lambdas example so... I wonder... What's the coolest (as in the most elegant) use of the C# LINQ and/or Lambdas/anonymous delegates you have ever saw/written? Bonus if it has went into production too! ...

Is there a Way to use Linq to Oracle

I can connect with the DataContext to the Oracle database however I get errors in running the query against the oracle database. I looked at the SQL generated and it is for MSSQL and not Oracle PSQL. Does anybody know of a decent easy to use wrapper to use LINQ against an Oracle Database? ...

Is there a pattern using Linq to dynamically create a filter?

Is there a pattern using Linq to dynamically create a filter? I have the need to create custom filtering on a list, in the past I would just dynamically create the SQL...it doesn't seem like this is possible with Linq. ...

How can I convert IEnumerable<T> to List<T> in C#?

I am using LINQ to query a generic dictionary and then use the result as the datasource for my ListView (WebForms). Simplified code: Dictionary<Guid, Record> dict = GetAllRecords(); myListView.DataSource = dict.Values.Where(rec => rec.Name == "foo"); myListView.DataBind(); I thought that would work but in fact it throws a System.Inva...

Linq select * with multiple tables

This query works great: var pageObject = (from op in db.ObjectPermissions join pg in db.Pages on op.ObjectPermissionName equals page.PageName where pg.PageID == page.PageID select op).SingleOrDefault(); I get a new type with my 'op' fields. Now I want to retrieve my 'pg' fie...

Data Conflict in LINQ

Hi, sorry if this is a really dumb question but I've not had a chance to really look deeply into it yet and I wondered whether somebody had a solution to the problem. When making changes using SubmitChanges() LINQ sometimes dies with a ChangeConflictException exception with the error message 'Row not found or changed', without any indic...

C# Linq Grouping

Hi, I'm experimenting with Linq and am having trouble figuring out grouping I've gone through several tutorials but for some reason can't figure this out. As an example, say I have a table (SiteStats) with multiple website IDs that stores a count of how many visitors by type have accessed each site in total and for the past 30 days. ...

Identify an event via a Linq Expression tree

The compiler usually chokes when an event doesn't appear beside a += or a -=, so I'm not sure if this is possible. I want to be able to identify an event by using an Expression tree, so I can create an event watcher for a test. The syntax would look something like this: using(var foo = new EventWatcher(target, x => x.MyEventToWatch) {...