iqueryable

WPF IEnumerable<T> vs IQueryable<T> as DataSource

冷暖自知 提交于 2019-12-08 13:29:26
问题 I have a WPF ListView and I bind it to a IEnumerable<T> collection. Everything works fine, but when I bind it to the IQueryable<T> collection, there are no items in list anymore.. Why? Is it not observable or what? When I look at the definition: public interface IQueryable<T> : IEnumerable<T>, IQueryable, IEnumerable and public interface IEnumerable<T> : IEnumerable so where is the problem? 回答1: It should work, as you correctly point out, these types are compatible. Turn on debugging in your

Can a LINQ to SQL IQueryable be unexpectedly evaluated?

筅森魡賤 提交于 2019-12-08 03:10:29
I am writing some code that takes a LINQ to SQL IQueryable<T> and adds further dynamically generated Where clauses. For example here is the skeleton of one of the methods: IQueryable<T> ApplyContains(IQueryable<T> source, string field, string value) { Expression<Func<T, bool>> lambda; ... dynamically generate lambda for p => p.<field>.Contains(value) ... return source.Where(lambda); } I might chain several of these methods together and finish off with a Skip/Take page. Am I correct in thinking that when the IQueryable is finally evaluated if there is anything in the lambda expressions that can

Equivalent of IQueryable in Spring Data

一个人想着一个人 提交于 2019-12-07 23:46:34
问题 I'm used to .Net and LINQtoEntities, especially the IQueryable part which allows to carry a request through different functions before fetching the results. Does anything like this exist in spring data ? Or any other java ORM ? Basic example of what I'd like to be able to do : private IQueryable<Todo> GetAll(){ context.Todos.Where(t => !t.Deleted); } public IEnumerable<Todo> GetDoneTodos(){ GetAll().Where(t => t.Done).ToList(); } 回答1: You can use Spring Data's QueryDSL integration. Basically,

When IQueryable returns no record ToList() throws an exception

江枫思渺然 提交于 2019-12-07 12:39:21
问题 dataContext.Geo_Countries.Where(c => c.Name.Contains(searchKey)).ToList(); when the IQueryable returns no records I get a value null exception. What is the solution? 回答1: I suspect you don't get the problem when there are no matches - I suspect you get it when there's a row in your database with no Name value. Either that, or you're doing something else which you haven't shown us. What does the stack trace look like? 回答2: try to use this code dataContext.Geo_Countries.Where(c => c.Name !=

How to return an IQueryable<Something> as an IQueryable<ISomething>

一笑奈何 提交于 2019-12-07 08:42:26
问题 I have a class Something that implements ISomething . How can I convert/cast from an IQueryable<Something> to an IQueryable<ISomething> . When I try to cast, I am able to compile, but the result of the cast is always NULL. Background: The reason I am doing this is because my Something class is a CodeSmith-generated class (PLINQO template) that has table mapping decoration, methods, etc. My ISomething interface is "POCO-style", in that it is dumb and simply mirrors the properties of the

NHibernate Linq Query with Projection and Count error

本小妞迷上赌 提交于 2019-12-07 07:37:58
问题 I have the following query: var list = repositoy.Query<MyClass>.Select(domain => new MyDto() { Id = domain.Id, StringComma = string.Join(",", domain.MyList.Select(y => y.Name)) }); That works great: list.ToList(); But if I try to get the Count I got an exception: list.Count(); Exception NHibernate.Hql.Ast.ANTLR.QuerySyntaxException A recognition error occurred. [.Count[MyDto](.Select[MyClass,MyDto](NHibernate.Linq.NhQueryable`1[MyClass], Quote((domain, ) => (new MyDto()domain.Iddomain.Name

Converting IQueryable<object> results to comma delimited string

大城市里の小女人 提交于 2019-12-07 06:43:17
问题 I have a LINQ query that returns all absences for an employee. The first part of the linq statement gets a basic list of the employees details, but I also return an IQueryable list of illnesses related to that absence. I'd like to somehow convert that IQueryable list to a comma delimited list of Illnesses. Currently I use (majorly stripped down): DetailsOfSickness = ( from t2 in Illnesses join ai1 in AbsenceIllnesses on t2.IllnessID equals ai1.IllnessID select new { Illness = ", " + t2

Using IQueryable<TEntity> instead DbSet<TEntity> problem

 ̄綄美尐妖づ 提交于 2019-12-07 02:22:38
问题 i stumbled to the next problem... I have database context: // For support unit testing... public interface IDbContext : IDisposable { IQueryable<Hardware> Hardwares { get; } IQueryable<ProviderHardware> ProviderHardwares { get; } } // Real DbContext (EF 4.0, Code First) public class PrimaryDbContext : DbContext, IDbContext { public DbSet<Hardware> Hardwares { get; set; } public DbSet<ProviderHardware> ProviderHardwares { get; set; } IQueryable<Hardware> IDbContext.Hardwares { get { return

What is a good way to to indicate an IEnumerable is “slow” or “fast”?

梦想与她 提交于 2019-12-07 01:10:26
问题 The answer to What is the expected performance of IEnumerable? says there's no way to know anyting about the performance of iterating an arbitrary IEnumerable. Each iteration could hit a database or make a web serivce call; or it might just return the next item in an array/list. Given that, is there a good way to indicate "this is fast"? For example, with T[] or List<T> instead of IEnumerable<T> I know that going from T[i] to T[i+1] will be quick. (Of course, forcing the enumeration to return

Adding new items dynamically to IQueryable hard-coded fake repository

北城余情 提交于 2019-12-07 00:06:29
问题 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}, new Product{ ProductID = "yyy", Description = "xxx", Price = 2000}, new Product{ ProductID = "zzz", Description = "xxx", Price = 3000} }.AsQueryable(); public IQueryable