iqueryable

NHibernate testing, mocking ISession

放肆的年华 提交于 2019-12-22 05:28:07
问题 I am using NHibernate and Rhinomocks and having trouble testing what I want. I would like to test the following repository method without hitting the database (where _session is injected into the repository as ISession): public class Repository : IRepository { (... code snipped for brevity ...) public T FindBy<T>(Expression<Func<T, bool>> where) { return _session.Linq<T>().Where(where).FirstOrDefault(); } } My initial approach is to mock ISession, and return an IQueryable stub (hand coded)

Unit Test IQueryable

别等时光非礼了梦想. 提交于 2019-12-22 05:16:29
问题 I am trying to write a unit test for a method which takes an IQueryable collection. How should I instantiate the collection in my unit test before I pass it to the method for test? This is the default code in my test IQueryable<Item> Items = null; // TODO: Initialize to an appropriate value And here is what I tried writing IQueryable<Item> Items = new IQueryable<Item>; // TODO: Initialize to an appropriate value Am I making a school boy error? 回答1: Well, you can use .AsQueryable() on any

IQueryable Extension Behavior Differing For Automapper Polymorphic Collection

爱⌒轻易说出口 提交于 2019-12-22 01:18:45
问题 Using Automapper 3.3.1.0 there is a different mapping behavior between the usage of Mapper.Map<IEnumerable<TDestination>>(someEnumerable) compared to someEnumerable.AsQueryable().Project().To<TDestination>() This does not appear to be a limitation of a SQL LINQ provider or other as this is witnessed in an in-memory collection. As with many things this is best explained by example: Note: the following code can be found at https://gist.github.com/kmoormann/b3949d006f4083ab6ee4 using System

Create fully dynamic where clause with expression tree and execute on IQueryable

做~自己de王妃 提交于 2019-12-21 12:10:59
问题 At point (3) in my code I have defined a query called query1 in which I defined a .Where lambda expression. This query is in some way dynamic but still contains static elements, it always refers to the Type Employee and its (int) property ClientID. Now I very much like to make the refering to the type and its property dynamic, based on the method parameters which by example are shown below point (1). What I tried to so far is making the static part of the query defined under point (3) fully

IQueryable Lambda Projection Syntax

前提是你 提交于 2019-12-21 04:59:11
问题 I have an IQueryable whose Entity Framework 4 objects I would like to project to their DTO equivalents. One such object 'Person' is an EF4 class, and the corresponding POCO PersonP is a class I've defined. I am using Automapper to map between them. However, when I try the following code: IQueryable<Person> originalModel = _repo.QueryAll(); IQueryable<PersonP> projection = originalModel.Select(e => Mapper.Map<Person, PersonP>(e)); The projection generates this error at runtime: LINQ to

refactoring LINQ IQueryable expression to remove duplicated portions of queries

半城伤御伤魂 提交于 2019-12-20 23:25:18
问题 I have some linq queries that have redundancy I'd like to factor out a single piece of code. These are join experssions that are IQueryable, and its important I don't cause the query to be evaluated earlier than it would be without the refactoring. Here is a simplified query: var result = from T in db.Transactions join O in db.Orders on T.OrderID equals O.OrderID join OD in db.OrderDetails on O.OrderID equals OD.OrderID into OrderDetails let FirstProductBought = OrderDetails.First().Select(OD

Dapper, ODATA, and IQueryable in ASP.NET

ぐ巨炮叔叔 提交于 2019-12-19 08:05:59
问题 I saw the great performance of Dapper and some samples of how to use it. I was wondering if I can use it to provide IQueryable data and integrate it with UI layer using ODATA to transfer data to the UI (like grids, lists,...). Is there any way to return Dapper objects AsQueryable instead of IEnumerable to query using ODATA? 回答1: No, not really. Well, you can wrap any sequence with .AsQueryable() if you really want, but it will just be using LINQ-to-Objects. Dapper is deliberately simple; it

Dapper, ODATA, and IQueryable in ASP.NET

偶尔善良 提交于 2019-12-19 08:05:50
问题 I saw the great performance of Dapper and some samples of how to use it. I was wondering if I can use it to provide IQueryable data and integrate it with UI layer using ODATA to transfer data to the UI (like grids, lists,...). Is there any way to return Dapper objects AsQueryable instead of IEnumerable to query using ODATA? 回答1: No, not really. Well, you can wrap any sequence with .AsQueryable() if you really want, but it will just be using LINQ-to-Objects. Dapper is deliberately simple; it

Cannot convert IQueryable<> to IOrderedQueryable error

早过忘川 提交于 2019-12-19 05:14:47
问题 I have the following LINQ code: var posts = (from p in db.Posts .Include("Site") .Include("PostStatus") where p.Public == false orderby p.PublicationTime select p); if (!chkShowIgnored.Checked) { posts = posts.Where(p => p.PostStatus.Id != 90); } That last line (the extra where) is giving me the error: Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IOrderedQueryable'. I'm not sure what this means... Why am I getting this error? It appeared once I added the "orderby"

Binding GridView to IQueryable<T>

安稳与你 提交于 2019-12-19 03:23:10
问题 This question is purely academic, because I'd never dream of doing this in real code. Using LINQ to SQL, I want to bind an IQueryable<T> to a GridView. I tried doing this with the following code, but I get the exception: Cannot access a disposed object. Object name: 'DataContext accessed after Dispose.'. Here is my code that gets an IQueryable<tabGenre> using LINQ to SQL: public static IQueryable<lu_Genre> GetGenres2() { using (BooksContextDataContext ctx = new BooksContextDataContext()) {