iqueryable

Linq based generic alternate to Predicate<T>?

时光总嘲笑我的痴心妄想 提交于 2019-12-30 08:25:53
问题 I have an interface called ICatalog as shown below where each ICatalog has a name and a method that will return items based on a Predicate<Item> function. public interface ICatalog { string Name { get; } IEnumerable<Item> GetItems(Predicate<Item> predicate); } A specific implementation of a catalog may be linked to catalogs in various format such as XML, or a SQL database. With an XML catalog I end up deserializing the entire XML file into memory, so testing each item with the predicate

IQueryable for Anonymous Types

那年仲夏 提交于 2019-12-30 08:15:33
问题 I use EntityFramework, I'm querying and returning partial data using Anonymous Types. Currently I'm using IQueryable<dynamic> , it works, but I would like to know if this is the proper way to do it or if there is some other returning datatype that I'm not aware of. public IQueryable<dynamic> FindUpcomingEventsCustom(int daysFuture) { DateTime dateTimeNow = DateTime.UtcNow; DateTime dateTimeFuture = dateTimeNow.AddDays(daysFuture); return db.EventCustoms.Where(x => x.DataTimeStart >

IQueryable vs. IEnumerable in the repository pattern , lazy loading

喜夏-厌秋 提交于 2019-12-29 05:07:18
问题 I have read some articles that state that IEnumerable used to mimic stored procedures or restrict your database. Lost lazy loading ability on the external provider. Where as IQueryable to give developers more flexibility. Lazy loading is there. In terms of performance, both consume a significant amount of performance .. so which one is more preferable? 回答1: From the perspective of a Repository Pattern, you can think of it this way: Use an eager loading IEnumerable when you want to pass an

IQueryable with Entity Framework - order, where, skip and take have no effect

自古美人都是妖i 提交于 2019-12-25 20:03:26
问题 I'm using Entity Framework (code first) like this: IQueryable<StammdatenEntityModel> query = dbSet; query.OrderByDescending(s => s.CreateDateTime); query.Where(s => s.Deleted == false); if(!String.IsNullOrEmpty(keyword)) { query.Where(s => s.SerialNumber.Contains(keyword)); //simplified for SO } query.Skip(skip); query.Take(take); However the OrderByDescending , Where , Skip and Take don't have any effect. 回答1: You are not using the result of query IQueryable<StammdatenEntityModel> query =

IQueryable convert int to string - sortOrder and Filtring

社会主义新天地 提交于 2019-12-25 09:43:19
问题 int' does not contain a definition for 'Contains' and the best extension method overload 'Queryable.Contains(IQueryable, string)' requires a receiver of type 'IQueryable This is part of the code of the Controller: var projects = db.Projects.Include(p => p.Engineer).Include(p => p.SiteLocation); // var projects = from p in db.Projects // select p; if (!String.IsNullOrEmpty(searchString)) { projects = projects.Where(p => p.NumberMCP.Contains(searchString) || p.nameProject.Contains(searchString)

Using pre-existing iqueryable to filter another iqueryable on Entity Framework

有些话、适合烂在心里 提交于 2019-12-25 03:55:32
问题 I have a many to many relationship (Sites, Categories, CategoriesXSite), I need to get all categories filtering by certain site names so I did my homework and made this linq: var filteredcategories = from c in context.Categories from s in c.Sites where s.Name.Contains(siteWord) select c; it works perfectly, the thing is I already have a method that filters sites and I want to reuse it like this: var filteredcategories = from c in context.Categories where c. Sites == FilterSites(siteWord)

EF Query with conditional include that uses Joins

给你一囗甜甜゛ 提交于 2019-12-25 01:27:17
问题 This is a follow up to another user's question. I have 5 tables CompanyDetail CompanyContacts FK to CompanyDetail CompanyContactsSecurity FK to CompanyContact UserDetail UserGroupMembership FK to UserDetail How do I return all companies and include the contacts in the same query? I would like to include companies that contain zero contacts. Companies have a 1 to many association to Contacts, however not every user is permitted to see every Contact. My goal is to get a list of every Company

Create custom objects from IQueryable without loading everything into memory

馋奶兔 提交于 2019-12-25 01:13:00
问题 This is a follow up question to this question. You should read that first. I have now, thanks to this answer, created a query that will return the correct entries. See: IQueryable<Data> onePerHour = dataLastWeek .Where(d => !dataLastWeek .Any(d2 => d2.ArchiveTime.Date == d.ArchiveTime.Date && d2.ArchiveTime.Hour == d.ArchiveTime.Hour && d2.ArchiveTime < d.ArchiveTime)); Now for processing the entries and displaying them on a chart, I only need one or two properties of the model class Data .

LINQ to entities does not recognise the method

烂漫一生 提交于 2019-12-24 13:59:53
问题 I understand why I'm getting the following error, however I'm not sure how I could go about providing a solution that can get around it. {System.NotSupportedException: LINQ to Entities does not recognize the method 'Boolean IsStatus(CDAX.DataModel.ProcessStatusEnum)' method, and this method cannot be translated into a store expression. I don't want to just return IEnumerable as I want to translate the filters to an underlying SQL statement so that I don't query on so many rows etc public

Error when trying to test an isolated IQueryable

元气小坏坏 提交于 2019-12-24 10:57:13
问题 Context: I want to test whether a piece of code that purports to layer some operations on top of an IQueryable<T> actually does so. But when I start with code that is known to work, and try to write a test to exercise it, I get an unintelligible error. Actual Question: I would like to understand that error, what it means, and why it is happening. Not an X-Y questions!! I'm not interested here in what the best way to achieve my original goal is, or whether this test would have achieved it. I'm