iqueryable

linq to sql ExecuteQuery() as IQueryable

ExecuteQuery() method returns an IEnumerable but is there a way to make it return IQueryable? ...

What am I Doing Wrong with IQueryable<T>?

I thought IQueryable<T> was derrived from IEnumerable<T>, so why can't I access the results of my query like a collection of records? public bool DoLogIn(System.String strUserName, System.String strPassword) { if (this.IsLoggedIn) return false; ASRDBDataContext ASRData = new ASRDBDataContext(); IQueryable<user> Curr...

Linq To Sql: Cannot implicitly convert type IEnumerable to IQueryable

Obfuscated Scenario: A person has zero, one or many pets. Using Linq to Sql, the need is to get an IQueryable list of pets for the given personID. Here's the poorly mangled/butchered/obfuscated portion of the ERD: Code: public IQueryable<Pet> GetPersonPets(int personID) { var personPets= from p in Person where ...

Why use AsQueryable() instead of List()

I'm getting into using the Repository Pattern for data access with the Entity Framework and LINQ as the underpinning of implementation of the non-Test Repository. Most samples I see return AsQueryable() when the call returns N records instead of List. Could someone tell me the advantage of doing this? Regards ...

where to find a small example/demo on how to create a LINQ Provider?

Hi i was wondering if you have had seen a quick demo on creating a LINQ Provider. Thanks, Oscar ...

Automatically Compile Linq Queries

We've found that compiling our Linq queries is much, much faster than them having to compile each time, so we would like to start using compiled queries. The problem is that it makes code harder to read, because the actual syntax of the query is off in some other file, away from where it's being used. It occurred to me that it might be ...

WPF IEnumerable<T> vs IQueryable<T> as DataSource

Hi. I have a WPF ListView and I bind it to a IEnumerable<T> collection. Everything works fine, but when I bind it to the IQueryable<T> collection, there are no items in list anymore.. Why? Is it not observable or what? When I look at the definition: public interface IQueryable<T> : IEnumerable<T>, IQueryable, IEnumerable and public...

What is the best way to cast each item in a LINQ to Entities query to in interface?

I have an entity object 'User' which implements 'IUser': IQueryable<User> users = Db.User; return users; But what I actually want to return is: IQueryable<IUser> So what is the best way to convert IQueryable<User> to IQueryable<IUser> without actually running the query? Right now I am doing this but it seems like a hack: IQ...

How to convert IQueryable to a List?

Hi guys, Just learning LINQ and i've come to a newbie roadblock in my test project. Can you explain what i'm doing wrong? public List<ToDoListInfo> retrieveLists(int UserID) { //Integrate userid specification later - need to add listUser table first IQueryable<ToDoListInfo> lists = from l in db.ToDoLists ...

Using linq2SQL to return a 1 to many relationship?

Hi there, is there a good way of of returning a 1 to many relationship from linq2sql, probably needs some explanation ! :-) Basically i have a table that has invoices and another table that is invoice details.. I have my linq2sql classes that were automatically created using linq2sql designer ... So to return the query where invoice ...

Cache strategies using IQueryables

I have been pondering for a while how to best cache IQueryables. I am using a repository pattern to fetch data into a class such as this one: public class Item { public int Id { get; set; } public string Name { get; set; } public IQueryable<Category> { get; set; } // For simplicity. It is actually a LazyList<Category> contai...

How to maintain LINQ deferred execution?

Suppose I have an IQueryable<T> expression that I'd like to encapsulate the definition of, store it and reuse it or embed it in a larger query later. For example: IQueryable<Foo> myQuery = from foo in blah.Foos where foo.Bar == bar select foo; Now I believe that I can just keep that myQuery object around and use it like I describe...

Why is my LINQ statement returning IEnumerable?

I have two very similar methods: public IQueryable<User> Find(Func<User, bool> exp) { return db.Users.Where(exp); } public IQueryable<User> All() { return db.Users.Where(x => !x.deleted); } The top one, will not compile, saying it returns IEnumerable rather than IQueryable. Why is this? Also, I am aware I can add "AsQueryab...

MVC LINQ to SQL JOIN for custom type fails for a strongly typed view

I have a simple data model of two tables, email and recipients, email can be sent to one or more recipients I have setup the database with the two tables, created the Linq to SQL repository, built the controllers and the strongly typed view. This works fine when I want to select all records from the database public IList<AllMailDetai...

Loading jqgrid from qury with multiple joins

I am trying to load a sortable jqgrid 3.5 from a query with multiple joins in it and having much difficulty as I am a novice with both Linq and jqgrid. In order to allow for sorting I first was attempting to load it using dynamic sql. Since I am pulling columns from multiple tables I assume my return will be a class object which I will p...

C#: Repository Methods vs. Extending IQueryable

Hello, I have repositories (e.g. ContactRepository, UserRepository and so forth) which encapsulate data access to the domain model. When I was looking at searching for data, e.g. finding a contact whose first name starts with XYZ a contact whose birthday is after 1960 (etc), I started implementing repository methods such as Firs...

IQueryable Count method takes longer to execute.

With a WCF built on top of a DB containing around 200 tables and Entity Framework, it takes lot of time (around 2 mins) to perform login the first time after building the WCF. Stepping into the code revealed the IQueryable.Count method to be the culprit. This happens only the first time after building the WCF code. Consecutive executio...

Pipes and Filters and CompiledQuery.Compile

Hi guys I have started using linq to sql and the entity framework and have found the development experience to be fairly good. Like the way you can break a query apart and combine different queries is quite nice - see pipes and filters. But the problem that I have found is that performance can be greatly increased (in my case by a fa...

Subsonic query with critera on a one-to-many relation

When using SubSonic 3.0 i have encountered a small issue that may be quite easy to solved, but please, enlight me with the solution :) I have a NewsArticle table with some news, each newsarticle can be published on different sites. So there is a Site table and also a NewsArticleSite table. The NewsArticleSite table contains a primary ke...

How to write a LINQ query to do this...

IQueryable<SomeType> result = (from x in Context.XXX select x); now what I need to do is the following (written pseudo code, I need actual code): foreach(var i in items) { // Where the object "i" has 2 properties // 1) i.Operator (values of which can be AND or OR) // 2) i.SomeID (values of which can be 1 .. 10) // I need to b...