iqueryable

Entity Framework - Querying from ObjectContext vs Querying from Navigation Property

北战南征 提交于 2019-12-10 18:13:53
问题 I've noticed that depending on how I extract data from my Entity Framework model, I get different types of results. For example, when getting the list of employees in a particular department: If I pull directly from ObjectContext, I get an IQueryable<Employee> , which is actually a System.Data.Objects.ObjectQuery<Employee> : var employees = MyObjectContext.Employees.Where(e => e.DepartmentId == MyDepartment.Id && e.SomeCondtition) But if I use the Navigation Property of MyDepartment, I get an

Cannot implicitly convert type System.Linq.IQueryable<string> to string

旧时模样 提交于 2019-12-10 15:13:47
问题 I have two tables named Rank and CrewMembers.I want to fetch the name of rank which is present in Rank table on the basis of id of CrewMember.I have passed the crewId as a parameter and on the basis of that the method would return the Rank of that specific Crew Member.This is how my code is- public string GetRank(int CrewId) { string rank = (from r1 in context.Rank join r2 in context.CrewMember on r1.RankId equals r2.RankId where r2.CrewId == CrewId select r1.RankName); return rank; } When I

Creating a dynamic query using IQueryable

佐手、 提交于 2019-12-10 14:48:34
问题 I'm trying to iterate for over an string array and dynamically create a IQueryable query. Its pretty straightforward but here's where I'm stuck var query = context.QuestionsMetaDatas.AsQueryable(); var keywords=new List<string>(){ "Test1","Test2" }; foreach(var key in keywords) { query=query.Where(a=>a.Text.Contains(key)); } Now the problem is that when the query gets generated its compiles to select * from QuestionsMetaDatas where Text Like "Test1" AND Text Like "Test2" Instead of AND I

IQueryable problems using WCF

孤街醉人 提交于 2019-12-10 03:56:25
问题 I have a quite simple WCF service method which returns an IQueryable, just for testing. Perhaps I got something wrong when trying to understand what IQueryable is designed for. I clearly plan to use this with the IQueryable provider of NHibernate later. But first I ran into some sort of serialization problems (at least I think it might be the problem) whenever using a WCF method returning an IQueryable. It doesn't even work for a simple string. Here's my code: public IQueryable<string>

How to maintain LINQ deferred execution?

荒凉一梦 提交于 2019-12-10 03:11:28
问题 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 described. But some things I'm not sure about: How best to parameterize it? Initially I've defined this in a method and then returned the IQueryable<T> as the result of the

Why using Count with IQueryable is considered unfeasible

非 Y 不嫁゛ 提交于 2019-12-10 02:06:23
问题 If I have the following code:- IQueryable<People> list = repository.FindAllPeople; int count = list.Count(); Then is it considered as unfeasible to count IQueryable objects and it is better to use IEnumerable? BR 回答1: You have been misinformed. IEnumerable will use Linq to objects, all methods are executed on objects in memory . - IQueryable will use whatever implementation of the Linq extension methods is provided by the specific provider. In this case (a repository) I would guess it is most

Entity Framework and Repository Pattern (problem with IQueryable)

巧了我就是萌 提交于 2019-12-09 11:00:47
问题 I just switched from Linq 2 SQL to Entity Framework, and I'm seeing some strange behaviors in EF that I'm hoping someone can help with. I tried Googling around, but I wasn't able to find other people with this same problem. I've mocked up a scenario to explain the situation. If I work directly with an EF context, I'm able to do a select within a select. For example, this executes perfectly fine: // this is an Entity Framework context that inherits from ObjectContext var dc = new MyContext();

What instantiate-able types implementing IQueryable<T> are available in .Net 4.0?

时光总嘲笑我的痴心妄想 提交于 2019-12-09 02:07:05
问题 Within the context of C# on .Net 4.0, are there any built-in objects that implement IQueryable<T> ? 回答1: IQueryable objects are produced by Queryable Providers (ex. LINQ to SQL, LINQ to Entities/Entity Framework, etc). Virtually nothing you can instantiate with new in the basic .NET Framework implements IQueryable. IQueryable is an interface designed to be used to create Queryable providers, which allow the LINQ library to be leveraged against an external data store by building a parse-able

Does AsQueryable() on ICollection really makes lazy execution?

本小妞迷上赌 提交于 2019-12-08 19:21:07
问题 I am using Entity Framework CodeFirst where I have used Parent Child relations using ICollection as public class Person { public string UserName { get;set} public ICollection<Blog> Blogs { get; set;} } public class Blog { public int id { get; set; } public string Subject { get; set; } public string Body { get; set; } } Ok, so far everything is working ok, but my concern is, whenever I want to get the Blogs of a person, I get it as var thePerson = _context.Persons.Where(x => x.UserName = 'xxx'

WebAPI OData $Skip on custom IQueryable double applied

不羁岁月 提交于 2019-12-08 17:47:07
问题 I have implemented a custom IQueryable that is exposed via a WebAPI OData endpoint. The structure of the controller's Get() is rather standard: [EnableQuery( AllowedQueryOptions = AllowedQueryOptions.Count | AllowedQueryOptions.Filter | AllowedQueryOptions.OrderBy | AllowedQueryOptions.Skip | AllowedQueryOptions.Top)] [ODataRoute] public PageResult<Foo> Get(ODataQueryOptions<Foo> queryOptions) { var bars = new QueryableData<Foo>(_provider); var result = ((IQueryable<Foo>)queryOptions .ApplyTo