iqueryable

LINQ & Enums as IQueryable

I basically have an enum public enum WorkingDays { Monday, Tuesday, Wednesday, Thursday, Friday } and would like to do a comparison against an input, which happens to be a string //note lower case string input = "monday"; The best thing I could come up with was something like this WorkingDays day = (from d in Enum....

How do I mock IQueryable<T>

I am creating a repository that exposes IQueryable. What is the best way to mock this out for my unit testing? Since I am using RhinoMocks for the rest of my mock objects, I tried to do the following: IQueryable<MyObject> QueryObject = MockRepository.GenerateStub<IQueryable<MyObject>>(); This doesn't work though so I tried doing...

Hashset vs. IQueryable

Recently I was working on implementing a small snippet that caches my results and the way I was doing it was using a Dictionary as follows: private Dictionary<ID, IQueryable<Results>> _simpleCache; The idea was to search for all the results that have the id specified by 'ID' and if the Dictionary contains the key == id, we simply sea...

IQueryable to ToList then Cache results

Hi Guys/Lady's , wondering can any one help me with the following problem/question. Am trying to cache Iqueryable converted tolist<> & get data back out of the cache. However, can't work out why it is not working. public class QDatalist { public int q_id { get; set; } public string title { get; set; } public int? marks { ge...

When does IQueryable execute the query?

Hi, Ive got the following code which I hacked together from website examples. It works nicely but I dont really understand how it works... public static Func<EuvaTransientDataContext, string, string, int, IQueryable<SecurityAudit>> MatchedIPAddressesAuditRecords = CompiledQuery.Compile((EuvaTransientDataContext db, string us...

Making linq avoid using in memory filtering where possible

Consider the these two LINQ2SQL data retrieval methods. The first creates a 'proper' SQL statement that filters the data, but requires passing the data context into the method. The second has a nicer syntax but loads the entire list of that accounts projects, then does in memory filtering. Is there any way to preserve the syntax of th...

LINQ to SQL - further modifying IQueryable result set with Contains

I am using LINQ to SQL and I am allowing users to set up the query via assigning values to queryStrings in the UI. I set up the primary query to return an IQueryable result and then keep refining the results set by continuing to act upon the resulting IQueryable object. Everything works fine and the code looks similar to this var result...

What's the difference between IQueryable and IEnumerable

I'm confused as to the difference. Being fairly new to .Net, I know I can query IEnumerables using the Linq extensions. So what is this IQueryable and how does it differ? ...

IQueryable IGrouping how to work

i return such type IQueryable< IGrouping<int, Invoice>> List() how can i work with it? like with generic List<Invoice> ? ...

IQueryable pipline, with inheriting ORM model

I am trying to implement a media library system, and I started out my design from the POCO. I am planning to decouple the actual data access from the object so that, I may persists the same object in XML or SQL. What I have in the design is: public abstract class MediaBase {} public class Image : MediaBase {} public class Movie : Medi...

Convert to list after Cast<T>

Hi, I need to convert an IQueryable to List(is it possible to convert to IList?). There had not been an problem if it was not that i need to Cast<T> because I have interfaces to my objects. I've tried most things but for some reason I must run Cast<T> first and then ToList() which generates System.NullReferenceException. How do I solve ...

Normalizing chains of .Skip() and .Take() calls

I'm trying to normalize arbitrary chains of .Skip() and .Take() calls to a single .Skip() call followed by an optional single .Take() call. Here are some examples of expected results, but I'm not sure if these are correct: .Skip(5) => .Skip(5) .Take(7) => .Skip(0).Take(7) .Skip(5).Skip(7) ...

Time to start returning IQueryable<T> instead of IList<T> to my Web UI / Web API Layer?

I've got a multi-layer application that starts with the repository pattern for all data access and it returns IQueryable to the Services layer. The Services layer, which includes all of the business logic, returns IList to the Controllers (note: I'm using ASP.NET MVC for the UI layer). The benefit of returning IQueryable in the data ac...

Cannot implicitly convert type 'System.Linq.IQueryable<int>' to 'int?'

Hi this is my code var cityList = from country in doc.Element("result").Element("cities").Descendants("city") select new { Name = country.Element("name").Value, Code = country.Element("code").Value, Co...

How to return an IQueryable<Something> as an IQueryable<ISomething>

I have a class Something that implements ISomething. How can I convert/cast from an IQueryable<Something> to an IQueryable<ISomething>. When I try to cast, I am able to compile, but the result of the cast is always NULL. Background: The reason I am doing this is because my Something class is a CodeSmith-generated class (PLINQO templa...

Returning IQueryable or Enumerated Object

Hello everyone, I was wondering about the performance difference between these two scenarios and what could the disadvantages be over each other? First scenario : public class Helper //returns IQueryable { public IQueryable<Customer> CurrentCustomer { get{return new DataContext().Where(t=>t.CustomerId == 1); } } public...

How to define a collection in a POCO in Entity Framework 4?

Lets say I've a Team class which contains 0 or more Players. The Player class is easy: public class Player { public long Id { get; set; } public string Name { get; set; } public Team Team { get; set; } } But whats the best to define the Team class? Option 1 public class Team { public long Id { get; set; } public...

System.Linq.Expressions.ExpressionVisitor is inaccessible due to its protection level

I'm trying to follow the instructions on Creating an IQueryable LINQ Provider, but when I implement the classes which inherit from ExpressionVisitor as instructed I am told that ExpressionVisitor is inaccessible due to its protection level. Am I missing something incredibly basic? ...

Linq filtering an IQueryable<T> (System.Data.Linq.DataQuery) object by a List<T> (System.Collection.Generic.List) object?

My IQueryable line is: // find all timesheets for this period - from db so System.Data.Linq.DataQuery var timesheets = _timesheetRepository.FindByPeriod(dte1, dte2); My List line is: // get my team from AD - from active directory so System.Collection.Generic.List var adUsers = _adUserRepository.GetMyTeam(User.Identity.Name); I ...

Enumerable.Empty<T>() equivalent for IQueryable

When a method returns IEnumerable<T> and I do not have anything to return, we can use Enumerable.Empty<T>(). Is there an equivalent to the above for a method returning IQueryable<T> ...