iqueryable

What's the difference between IOrderedQueryable and IQueryable?

I have this: var points = from p in ContextDB.Points orderby p.PointInTime descending where p.InstanceID == instanceId && p.ParentPointID == null && p.PointTypeID == currentPointTypeID select p; and this: var points = from p in ContextDB.Poin...

What is actually happening with IQueryable.Where()?

This is is returning a boolean based on whether or not there are some matching IDs. from t in getAll select new Result { ... bool DetailsAvailable = (db.SaveTrackings.Where(s => s.BundleID == t.bundleID && s.UserID == t.userID) .Count() > 0) ? true : f...

IQueryable Entity Framework Foreign Key Table Value

Hello, I am having an issue with querying the entity framework (.net 4.0). I have the following: public IQueryable<Comment> GetComments(string section, int sectionId) { var query = from comm in ObjectContext.Comments.Where(id => id.SectionId == sectionId && id.CommentSection == section) select comm; return query; } N...

How can I refactor this IQueryable<T> Repository Method?

Hi Guys, I'm working on a .NET 4 application, C#, Entity Framework 4, SQL Server 2008. I have a 7 tables in my database, each representing a specific level of location (Country, State, City, Neighborhood, etc). Now in my Repository I am trying to define an interface contract which has only one Find() method. To do this, I've created ...

Sorting collection and sub-collection at the same time.

I have an IQueryable<Product> that needs to be sorted by Name. Each Product has an IQueryable<Category> that also needs to be sorted by Name. I'm having a hard time expressing this in Linq. I could loop through the products and sort each category list, but it seems messy. Hoping a Linq ninja has a smarter solution. My Product class look...

Entity Framework 4: Returning IQueryable or ObjectQuery when using LINQ to Entities?

Hi there, i have been reading when using Linq to entites a query is of type IQueryable before it is processed but when the query has been processed, it's no longer an IQueryable, but an ObjectQuery. In that case, is it correct to write methods from my layer (repository layer) to return IQueryable? Do i need to cast? Why would i want ...

IQueryable Repository with StructureMap (IoC) - How do i Implement IDisposable?

If i have the following Repository: public IQueryable<User> Users() { var db = new SqlDataContext(); return db.Users; } I understand that the connection is opened only when the query is fired: public class ServiceLayer { public IRepository repo; public ServiceLayer(IRepository injectedRepo) { this.repo = injec...

IQueryable OfType<T> where T is a runtime Type

I need to be able to get something similar to the following to work: Type type = ??? // something decided at runtime with .GetType or typeof; object[] entityList = context.Resources.OfType<type>().ToList(); Is this possible? I am able to use .NET 4 if anything new in that allows this. ...

LINQ where clause running against mapped object

If I want to run something like this BLL.Person person = (BLL.Person)repository.Single(item => item.Id == Id); Down in my single method I'd do something like this: public Resource Single(Expression<Func<BLL.Resource, bool>> where) { Resource resource = AsQueryable().FirstOrDefault(where); return resource; } protected IQuer...

IQueryable: Creating dynamically an OR filtering

I have a set of search criterias in this form: member | value | operator --------+---------+--------- height | 10 | > height | 2 | < name | Carl | == And I want to query all the objects that match any of these criterias. Right now, I'm doing it by: building an expression for each one of the crit...

How do I keep an IQueryable<> within a transaction using the repository pattern?

According to NHProf, the use of implicit transactions is discouraged: http://nhprof.com/Learn/Alerts/DoNotUseImplicitTransactions However, NHibernate LINQ returns an IQueryable<> when reading objects from the database, and this is lazily evaluated. I have this method in a repository: public IQueryable<T> GetAll<T>() { using (var t...

Adding new items dynamically to IQueryable hard-coded fake repository

Building an application, before using a real database, just to get things work I can first use a hard-coded list as a fake, in-memory repository: public class FakeProductsRepository { private static IQueryable<Product> fakeProducts = new List<Product> { new Product{ ProductID = "xxx", Description = "xxx", Price = 1000}, ...

Using LINQ-to-NHibernate Sort an IQueryable of T based on a property value within T's Children

Though the project in which I'm having this issue addresses a different domain, I've found a metaphor that may help to present my question clearly: Let's say that you had to develop a Forum web site, and it was a requirement that the default view for the site needs to display Forum Threads ordered by the threads with the most recent For...

Why is my IQueryable LINQtoObject being treated as LINQtoSQL and throwing no supported translation to SQL

I have a LINQ dbml class that I am wrapping in a POCO. I have built overloaded constructors that take the DBML class and init. the wrapper objects properties based on the dbml object passed in. For example public class MyPerson{ public MyPerson(DBMLPerson p) { this.ID = p.ID; this.Name = p.Name; } } if I the...

How to use IQueryable types in DataGridViewColumnCollection in WinForm

I want to set DataGridView's columns to ReadOnly except one or two columns. I was trying to do this. dgv.Columns.AsQueryable().ForEach(col=>col.ReadOnly=true); But I found that these extension methods are not available at DataGridViewColumnCollection How can I do the same by this way ...

Applying like filter to an IQueryable

I'm trying to write a custom filter for Dynamic data that will allow me to run like type queries on entity columns. For example searching for john on name field to returen johnson, johns etc. I'm trying to override the IQueryable GetQueryable(IQueryable source) method on the QueryableFilterUserControl class. To filter my results. Does a...

How to make IQueryable<out T> work with a reqular IQueryable?

I am using Linq2SQL and working with a legacy system. The system was built in .Net but without a datalayer so I am transcoding it so that it will have one. I have a linq query that looks like this... var data = from p in db.tblPeoples orderby p.strLastName,p.strFirstName select new ...

How can I get an IList of entites and their child objects in Entity Framework efficiently?

That is, I want to do this: var lists = (from list in this.DB.Lists select new { List = list, Items = list.ListItems.ToList(), }).ToList(); But, obviously, the Entity Framework doesn't support the ToList extension method in the select clause. What should I do? ...

How can I condense the following Linq query into one IQueryable

I have an EntityFramework model that has User entity that has an EntityCollection of Organisations. For a particular User I am trying to write a Linq Query to return the names of the organisations that the user belongs where that query will hit the db only once. My problem is that I cannot see how to write this query without having to ...

Error in IQueryable + foreach

I just want to know if there is any known issue, or if I'm doing something wrong. Everytime I do something like the example below, I get an error "the server failed to resume the transaction". I had already asked another question about this error, but now I've figured out it only appears in the foreach loops //Listing orde...