FAQ Database Discussion Community


Generic IQueryable to CompareDate

c#,linq,generics,iqueryable
so I'm trying to create a function that takes in an IQueryable, and a DateTime Property in that IQueryable, and returns an IQueryable which is compared against another datetime. Currently, I would have to do this for several different functions and this code may be subject to change so I...

SUPER SIMPLE LINQ to filter row does not work [closed]

linq,iqueryable
Spent about 4 hours trying to figure this out without success. IQueryable<userTOM> Infolist = userTOMs(); var rbtUserId = Infolist.Where(x => x.UserName == FormsUserName); userTOMs <-- Does not exist. Remade the namespace many times but will not appear. ...

IRavenQueryable Search can't find &-sign (or other special characters)

c#,search,escaping,ravendb,iqueryable
In our own RavenQueryableExtensions class we have the following method: public static IRavenQueryable<T> SearchMultiple<T>(this IRavenQueryable<T> self, Expression<Func<T, object>> fieldSelector, string queries, decimal boost = 1, SearchOptions options = SearchOptions.Or) { if (String.IsNullOrEmpty(queries)) throw new ArgumentNullException("queries"); // More than two spaces or tabs are replaced with a single space var newQueries...

Chaining together IQueryable in an OR fashion

linq,iqueryable
I've got some IQueryables I would like to OR together. My understanding is chaining them together using Where results in ANDing them together (though my understanding may be faulty.) Here's an example of a query I would like to OR together, in lieu of using all the chained Where clauses:...

How can I force EF to use joins instead of splitting up a complicated query?

c#,entity-framework,entity-framework-6,iqueryable,deferred-execution
I have a complex IQueryable that I would like EF to populate with a single database query so that I can use it with deferred execution. Please consider the following example. For these models: public enum AlphaState { Unknown = '\0', Good = 'G', Bad = 'B' } [Table("MY_ALPHA")] public...

Enforce ordering of OData items even when $top is used

linq,entity-framework,asp.net-web-api,odata,iqueryable
I have a DbSet<Items> collection. The primary key is a Guid. I don't want to order by this primary key. I want to order by an editable decimal property named "Order". The code I have is very simple, and it works great until the user puts a "$top" parameter into...

Lambda Linq Iqueryable group - add another grouping

c#,linq,lambda,group,iqueryable
I have a method that I use for generating a summary report, based on the options a user selects in pick lists, to count the number of a type of test that is completed in a region, with subset locations, within a date range. Here's what the data looks like:...

Trouble combining Linq Expressions into a Func

linq,nhibernate,ienumerable,iqueryable
I've been trying to factor some common lambda subexpressions out into reusable components and have hit a wall. I'll show what I've done so far with a simplified example and hope one of you can shed some light. My subexpressions are ultimately used in an NHibernate Query (IQueryable interface). Here's...

IQueryable where clause

c#,linq,iqueryable
Was difficult for me to find a fitting title for this post. But I have the following: IArticleRepository articleRepo = unitOfWork.ArticleRepository; List<Article> articles = new List<Article>( articleRepo.GetAll() .Where(a => a.Title == searchTerm) //.Where(a => a.Categories.Contains(Category.)) .OrderByDescending(a => a.CreatedDate)); So some explanation: An article has , among other things, a Title...

.NET LINQ IQueryable: what is `Expression` for?

.net,linq,iqueryable
I'm working on a LINQ provider so am implementing IQueryable. What is the purpose of the Expression property within this interface? I normally just return something like Expression.Constant(this) from my implementations, but have no idea if that's bad. Bizarrely the documentation states "This allows the framework to differentiate between LINQ...

Return IQueryable from my method? Is it the right way to do it?

c#,linq,expression,iqueryable
I just spent some time to find how to return an IQueryable from a method... and I'm still wondering if it is the right way to do it. Here is my repository class: public class CarRepository : ICarRepository { // Fake entities private IList<Car> _entities = new List<Car>() { new...

IRavenQueryable for both space-splitted search-terms and complete search-string as whole

c#,search,full-text-search,ravendb,iqueryable
In our own RavenQueryableExtensions class we have the following method: public static IRavenQueryable<T> SearchMultiple<T>(this IRavenQueryable<T> self, Expression<Func<T, object>> fieldSelector, string queries, decimal boost = 1, SearchOptions options = SearchOptions.Or) { if (String.IsNullOrEmpty(queries)) throw new ArgumentNullException("queries"); // All gabs of more than a single space (like tabs, two spaces, etc.) //...

Determine IQuerable column type based on name

linq,types,iqueryable
I have an iQueryable dataset. I wish to be able to determine the type of data based on the name. I am doing a linq query into a view model and I wish to get the type of column by name from the resulting query...

In which cases do I need to create two different extension methods for IEnumerable and IQueryable?

c#,.net,linq,ienumerable,iqueryable
Let's say I need an extension method which selects required properties from the collection. This can be entity or .net collection. So I have defined such extension method: public IQueryable<TResult> SelectDynamic<TResult>( this IQueryable<T> source, ...) This works fine for IQueryables. But, I also need to call this function for IEnumerables....

Send an IQuereyiable of arbitrary type to a general method

asp.net-mvc,entity-framework,iqueryable
The problem: I am trying to create a general method that will take in an IQuereyiable which can be many different types of data including custom. In this method I will be doing a sort depending on the type of IQuereyiable that is being passed in. What I am doing...

How to validate errors for items in IQueryable collection?

c#,error-handling,iqueryable,linq-to-excel
Let's say I have a class TmpClass, I use this class for returning data from Excel sheet using LinqToExcel ExcelQueryFactory. In this class I need to implement some logic to check data correctness. When I retrieve data from Excel sheet using ExcelQueryFactory it returns ExcelQueryable (which descends from IQueryalbe) There...