iqueryable

Linq to Sql: Add additional data to result

Hi, Bumped into a strange situation here. Trying to extract cars from a sql database within a certain range of a position (lat/long) and return an IQueryable to do additional logic on the resultset afterwards. public IQueryable<Car> QueryAllCarsByDistance(float latitude, float longitude, int distance) { var cars = from car in Query...

Performing part of a IQueryable query and deferring the rest to Linq for Objects

I have a Linq provider that sucessfully goes and gets data from my chosen datasource, but what I would like to do now that I have my filtered resultset, is allow Linq to Objects to process the rest of the Expression tree (for things like Joins, projection etc) My thought was that I could just replace the expression constant that contain...

How do I access consecutive elements in an IQueryable<T> object?

I need to access the current and previous element in an IQueryable object. If I had an int array, I would do the following: var array = new int[]{0,1,2,3,4}; for(var i = 1; i<array.Length ; i++) { method1(array[i-1], array[i]); } I don't know to do the same with IQueryable, since it does not implement IList. ...

HtmlEncode string within IQueryable without altering bound data

I'm binding an ASP.NET control to the result of a LINQ query. I'd like to HtmlEncode one of the properties of the contained objects before binding to the control, but I want to do it without altering the data because I do a DataContext.SubmitChanges() later on. How can this be done? Code that won't work: var ds = (from s in dc.Search...

To return IQueryable<T> or not return IQueryable<T>

I have a repository class that wraps my LINQ to SQL Data Context. The repository class is a business line class that contains all the data tier logic (and caching and such). Here's my v1 of my repo interface. public interface ILocationRepository { IList<Location> FindAll(); IList<Location> FindForState(State state); IList<L...

refactoring LINQ IQueryable expression to remove duplicated portions of queries

I have some linq queries that have redundancy I'd like to factor out a single piece of code. These are join experssions that are IQueryable, and its important I don't cause the query to be evaluated earlier than it would be without the refactoring. Here is a simplified query: var result = from T in db.Transactions join O in db.Orders...

How do you stub IQueryable<T>.Where(Func<T, bool>) with Rhino Mocks?

In the .net 3.5 project that I am working on right now, I was writing some tests for a service class. public class ServiceClass : IServiceClass { private readonly IRepository _repository; public ServiceClass(IRepository repository) { _repository = repository; } #region IServiceClass Members pu...

Force an IQueryable to execute?

I have a method that 'has no translation to SQL' that I want to perform on an IQueryable, is there a way to force the IQueryable to execute without having to store it in some intermediate class? ...

IQueryable, Where, Guid and

I'm working my way through the MVC Storefront code and trying to follow the path of a repository, a service and a model that is a poco, outside of the dbml/data context. It's pretty easy to follow actually, until I started writing tests and things failed in a way I just don't understand. In my case, the primary key is a uniqueidentifier...

LINQ to resx?

I'm trying to build a way to get the key for a given piece of text in a given resx file at runtime. Currently, I can open and read the file (Using ResXResourceReader) but I have to use a foreach to go over the entire file. This could be a performance issue, as some of our resx files are fairly large (in the order of 2000 strings) and w...

nHibernate IQuearable<T>

I have seen many nice things coming up for ASP.NET 4 and Silverlight 3. The best thing i've seen is the DomainDataSource where one can create a nice separation of Business and Data Layers and present the BL in both SL and ASP.NET. These examples make heavy use of IQuerable. My question to my fellow developers is: How can I implement I...

How can I return a IQueryable in C# 3.0 without knowing its type?

Hi! I have a method where I execute a query SQL (I'm using Linq to SQL but I have to execute a classic SQL query), but I don't know from which table/Entity this query will be generated. So, I was thinking that as I don't know from what Table the query will be generated from, I don't know the type of my IQueryable, am I right? But I do...

How should i lazy-generate a thumbnail image?

For background, i have a Data layer and Service layer loosely based on Rob Conery's Storefront model and like Rob's, many of my domain objects and chained with LazyList<>'s and LazyItem<>'s to make use of the deferred execution that Linq2Sql provides given that my Lazy* types utilise IQueryable<T> rather than this awesome delegate approa...

IQueryable Where Extention Method with Or's

Duplicate: http://stackoverflow.com/questions/782339/how-to-dynamically-add-or-operator-to-where-clause-in-linq I want to loop through a array of string values and build a linq expression Where each item in the list is OR'ed together. string[] search = new string[]{"A", "B", "C"}; foreach (string item in filterValues) { se...

Extend IQueryable<T> Where() as OR instead of AND relationship

I am using my own extension methods of IQueryable<> to create chainable queries such as FindAll().FindInZip(12345).NameStartsWith("XYZ").OrderByHowIWantIt() etc. which then on deferred execution creates a single query based on my extension methods chain. The problem with this though, is that all Where's in the extension chain (FindXYZ, ...

How do I cache an IQueryable object?

I've got this method that returns a Linq-to-SQL query for all the rows in a 'UserStatus' table: public IQueryable<BLL.Entity.UserStatus> GetAll() { var query = from e in _SelectDataContext.UserStatus select new BLL.Entity.UserStatus { UserStatusId = e.UserStatusId, En...

How can I write a clean Repository without exposing IQueryable to the rest of my application?

So, I've read all the Q&A's here on SO regarding the subject of whether or not to expose IQueryable to the rest of your project or not (see here, and here), and I've ultimately decided that I don't want to expose IQueryable to anything but my Model. Because IQueryable is tied to certain persistence implementations I don't like the idea ...

How can i convert IQueryable<string> to a string array?

Hi, if I do this... rowNames = _myDB.RowSet.Where(r => (r.RowId >= minId) && (r.RowId <= maxId)) .Select(r => r.RowName); it returns an IQueryable, how can I put this into: string[] myStringArray? ...

Explain in small words why IQueryable<T> is needed

There's this. Can you do a better job explaining (in small words so I understand :)) why we need a marker interface which doesn't add any methods over IEnumerable? ...

Searching for object in IList or IQueryable

Hi There I need to find a match of an item in a IQueryable list. I have a list as follows: IQueryable<EventItem> eventItems = new Queryable<EventItem>(); EventItem eventItem1 = new EventItem("Event 1"); EventItem eventItem2 = new EventItem("Event 2"); eventItems.Add(eventItem1); eventItems.Add(eventItem2); I now want to find the eve...