eager-loading

Rails Error: joins + include

I have the following models: class Person < ActiveRecord::Base has_many :images has_one :preference end class Image < ActiveRecord::Base belongs_to :person end class Preference < ActiveRecord::Base belongs_to :person end I am trying to fetch all images that are public and at the same time eager load the people who own those imag...

Linq-To-Entities Include

I'm currently learning a bit more about Linq-To-Entities - particularly at the moment about eager and lazy loading. proxy.User.Include("Role").First(u => u.UserId == userId) This is supposed to load the User, along with any roles that user has. I have a problem, but I also have a question. It's just a simple model created to learn a...

Eager loading and repository pattern

I'm wondering how to properly handle eager-loading problem for complex object graphs when using Repository pattern. This isn't ORM specific problem i guess. First try: public interface IProductRepository : IRepository<Product> { Product GetById(int id); IProductRepository WithCustomers(); } This would work fine, but that would in...

Having troubles loading related entities (Eager Load) with ObjectContext.CreateQuery (Entity Framework and Repositories)

Here's a bunch of things I tried... hopefully you can extrapolate from it what I'm trying to do and what I'm doing wrong. Okay so I'm having problems with loading related entities when using this DoQuery: public ObjectQuery<E> DoQuery(ISpecification<E> where) { return (ObjectQuery<E>)_ctx.CreateQuery<E>("[" + typeof(E).Nam...

How to do the opposite of eager-loading in Entity Framework?

I understand in Entity Framework you can specify relationships that need to be joined with Include: Product firstProduct = db.Product.Include("OrderDetail").Include("Supplier").First(); But we have the opposite issue that a simple LINQ statement is getting making too many JOINs on the SQL server. So how do we do the opposite...

Why is ToLookup() dependent on load options in Linq2Sql?

Lets say I have 3 tables Posts, PostTags and Tags defining a many-to-many relationship. I want to get a lookup table that will give me all the Posts related to a given tag so I use the following code: return dataContext.PostTags.ToLookup(pt => pt.Tag, pt => pt.Post); In unit test all went fine but in the real application, it didn't wo...

How can I do this Eager Loading (using the .Include() method) in this code?

Hi folks, I have a very simple repository I'm playing around with, using Entity Framework v4 that comes with VS2010 Beta 2. I'm trying to dynamically include the Include method, if a user optionally asks for it. eg. Public IQueryable<Foo> GetFoos(bool includeBars) { var entites = new Entities("... connection string ... "); v...

Eager Loading on tracked items?

I have an element bound to an entity (Contact) that exposes some navigation properties. I want, that on some action (i.e. a "Load children" button), the Contact should load for all its children and grand children like I can do with an ObjectQuery.Include before the execution; example (pseudo): DirectCast(element.DataContext, Contact).S...

Grails GORM Domain class relationship

Grails 1.1.1 Goovy 1.5.7 In a relationship such this: Author 1 -- n Book n -- 1 Publisher Defined in Grails: class Author { String firstName String lastName static hasMany = [books: Book] static constraints = { books(nullable: true) } } class Book { String title Author author Publisher ...

Rails ActiveRecord - eager loading (sort of) when using 'build' from has_many

I have a situation where children are built but not saved, and are then being used in the view with references to the parent. This leads to extensive use of rails record caching. I'd like to have the parent 'eager loaded' with the unsaved children records. class Parent < ActiveRecord::Base has_many :children def make_children lo...

Efficiently selecting a tree in Linq-To-Sql

Hello! I have a linq-to-sql data layer, with 2 tables in it. "Parent" and "Child". There's a relationship between Child and Parent (so parent has many children, etc etc), a parent can also have many parents (when children grow up and themselves become parents). I want to display this hierarchy out to the user, but I'm not sure how to...

Preferred way to convert from Lazy/Delay-loading to Eager-loading in an API?

I've been working on an API (which wraps a web-service of sorts) for a while now, and its just about feature complete. I initially designed this API to be lazy/delay-loaded throughout; which makes perfect sense if you're only interested in a small subset of the available data given the latency inherent in consuming a web-service. Howev...

Rails add custom eager load

I have a number of custom find_by_sql queries in Rails. I would like to use eager loading with them but there doesn't seem to be a good way to do this. I have seen the eager_custom.rb file floating around and it doesn't seem to work with Rails now. It appear Rails does eager loading differently now, using 2 queries (the regular query ...

Eager loading / prefetching many-to-many without LoadOptions - Linq to Sql

I've got a situation where I need to prefetch some entities through a many-to-many relationship. So it's like the classic BlogPost <- BlogPostTag -> Tag situation. Yes, I'm aware of LoadOptions but I can't use it because it's a web application and I'm using the one datacontext per request pattern. It also seems you can't use projection...

How can I do an eager load when I don't know the name of the property I want to load?

I have a generic repository and when I'm using a DoQuery method to select objects from the database, I need to load some of the related entities in order to not get nulls in the place of the fields that are foreign keys. The problem is that the repository is generic, so I do not know how many properties need loading or what their names ...

How do I set the Fetchmode on all assocations of a nHibernate ICriteria in one go?

I have an object that has many assocations to other objects. All of these are fetched lazily by nHibernate, which is good in almost all cases. In a particular scenario, in this case an export of a lot of records, I want to set the Fetchmode to eager on all associations. Is there a way to do this, without having to manually specify each...

Optimize Rails eager loading query for find all

In a Rails 2.3.5 application I've got something like the following models: class Foo < ActiveRecord::Base has_many :bars end class Bar < ActiveRecord::Base belongs_to :foo end And when I'm calling Foo.all(:include => :bars) I see the following queries in console: SELECT * FROM "foos" SELECT "bars".* FROM "bars" WHERE ("bars...

Rails Eager Loading on All Finds

OK, I've been playing around with some of the eager loading things, and have 2 models something like: Class Recipe < ActiveRecord::Base belongs_to :cookbook has_many :recipetags end and Class Cookbook < ActiveRecord::Base has_many :recipes, :include => [:recipetags] end Which is working out well, when I find a Cookboo...

GAE datastore eager loading in python api

I have two models in relation one-to-many: class Question(db.Model): questionText = db.StringProperty(multiline=False) class Answer(db.Model): answerText = db.StringProperty(multiline=False) question = db.ReferenceProperty(Question, collection_name='answers') I have front-end implemented in F...

ADO.Net Eager Loading Recasting Into Entities

I'm using Eager Loading to bring back 2 types of entities that I later want to put into IEnumberables of the respective types to do work with. crocodileEntities proxy = new crocodileEntities(new Uri("CrocodileDbDataService.svc", UriKind.Relative)); var ProjectionsQuery = from OptionARMRuns in proxy.OptionARMRuns.Expand("OptionARMRunI...