eager-loading

Eagerly loading entities in Linq2Sql

I’m trying to eagerly load an entity and its related properties (basic one to many) using the LoadWith and AssociateWith DataLoadOptions. However, after looking at the generated SQL I noticed that the statements generated by LoadWith are all Left Outer Joins. So the code below generates all left outer joins to fetch the data of the a...

Entity-Framework eagerly-load first item of a nav-property

Is there a way to make this code excute in one query with Entity-Framework? Private Sub LoadFirstPhone(vendor As Vendor) If Not vendor.ContactReference.IsLoaded Then _ vendor.ContactReference.Load(MergeOption.AppendOnly) vendor.Contact.Phones.Load(MergeOption.AppendOnly) End Sub I want two things: I want to be able...

NHibernate - define fetching strategy dynamically

Let me explain the problem - hopefully I have defined it well in the title but I want to be sure. I have a linq query that pulls back a bunch of objects (say Foos). Each Foo holds a reference to a User. Each User holds a reference to a Person: public class Foo { //properties omitted... public User CreatedBy {get;} } public class Us...

Problem with eager loading of nested models

Hi, I have some models - NewsArticle, Comment, User (as :author) and Profile. class NewsArticle < ActiveRecord::Base belongs_to :author, :class_name => "User", :foreign_key => "user_id" has_many :comments, :as => :commentable, :dependent => :destroy, :order => 'created_at', :include => 'translations' end class Comment < ActiveRecor...

Bounding an eagerly fetched collection

How can I eagerly fetch a collection, but just the N first items? Using this code works, but is there an 'official way' to achieve that? public Gallery GetById(int id) { var session = GetSession(); var criteria = session.CreateCriteria<Gallery>() .Add(Expression.Eq("Id", id)) .SetFetchMode("Pictures", FetchMod...

Entity Framework - what's the difference between using Include/eager loading and lazy loading?

I've been trying to familiarize myself with the Entity Framework. Most of it seems straight forward, but I'm a bit confused on the difference between eager loading with the Include method and default lazy loading. Both seem like they load related entities, so on the surface it looks like they do the same thing. What am I missing? ...

memcached as an Object store in Rails

I am using Memcached as an Object Store with my Rails application where I store search results which are User objects in memcached Now when I fetch the data out I get the Memcached Undefined Class/Module Error. I found a solution for this problem in this blog http://www.philsergi.com/2007/06/rails-memcached-undefinded-classmodule.html...

Nhibernate - Paging and eager loading entities

I have two entities, a team and an employee. I want get a list of employees with eager loaded teams. The list has to be paged. public PagedList<Employee> GetAllEmployeesWithEagerLoadedTeams(int page, int pageSize) { var criteria = GetSession() .CreateCriteria(typeof (Employee)) .SetFetchMode(DomainModelHelper.GetAss...

EF4/Linq Eager Loading with Include fails to populate all results

Hi, I'm trying out EF4 as part of a .Net 4.0 WCF service. The aim of the service is to return document data as an array of entity objects to any of our ASP.Net apps. The apps are still in .Net 2.0. Due to the nature of the solution I've disabled LazyLoading at context level. I started with this: var revQuery = from revs in context.t...

Can't Get EF4 Eager Loading of Subclassed Entities to Work

I have an abstract Content entity in my EF4 model with a concrete subclass, MultipleChoiceItem. There is a related table in the case of MultipleChoiceItem accessed by a Navigation property on the MultipleChoiceItem entity called Options. I would like to eager-load the Options result because if you're getting a MultipleChoiceItem, you alw...

Entity Framework - Eager loading related entities

I'm using Entity Framework 4 with MVC and need to ensure any referenced entities I want to use in my view have been loaded before the controller method returns, otherwise the view spits out the dreaded: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. When selecting s...

groovy / grails / hibernate - configure set to be fetched eagerly

We are configuring hibernate with grails using the domain classes. Added: static hasMany = [image:Image] static fetchMode = [image:"eager"] However, when I pull the object graph each image is not loaded. Please advise. Thanks. ...

Can I eager load a property using HQL?

I'm trying to work out how to eager load the customers in the following HQL query: select order.Customer from Order as order where order.Id in ( select itemId from BadItem as badItem where (badItemType = :itemType) and (badItem.Date >= :yesterday) ) There's the usual many-to-one relationship between orders and customers. I'd li...

How to properly manage NHibernate eager loading?

Currently I'm writing strategies for various purposes. Like this one: namespace x.Persistence{ using Domain; using NHibernate.Linq; public class ApplicationDefaultEagerLoading :IEagerLoadingStrategy<Application>{ public virtual INHibernateQueryable<Application> Attach(INHibernateQueryable<Application> q){ q.E...

EF: Lazy loading, eager loading, and "enumerating the enumerable"

I find I'm confused about lazy loading, etc. First, are these two statements equivalent: (1) Lazy loading: _flaggedDates = context.FlaggedDates.Include("scheduledSchools") .Include ("interviews").Include("partialDayAvailableBlocks") .Include("visit").Include("events"); (2) Eager loading: _flaggedDates = context.FlaggedDates; In oth...

No eager loading when rendering anything else than :action => "index"

Using Rails 2.3.8 I've experienced the following problem. Eager loading works fine When I have a controller like this: def alternativeview @books = Book.all :include => :author respond_to do |format| format.html { render :action => "index" } end end However, if I want to render this action with a different html....

Using Linq-to-SQL preload without joins

Like many people, I am trying to squeeze the best performance out of my app while keeping the code simple and readable as possible. I am using Linq-to-SQL and am really trying to keep my data layer as declarative as possible. I operate on the assumption that SQL calls are the most expensive operations. Thus, I try to minimize them in qu...

Possible to eager load associations with nested_attributes?

Just briefly, I have run into a dreaded 2(n) queries problem. If n = the number of skills in the database, then my characters#edit form will take 2(n) queries to load the page. It will SELECT a PlayerSkill (the join table) once every skill, and it will look up the Skill once per skill. Here is some code which I believe is pertinent to t...

NHibernate eager loading one-to-many

Hi In the mapping-file I've defined a bag for Positionen. <class name="Animag.DomainModels.Models.Abrechnung, Animag.DomainModels" table="Abrechnungen" lazy="true"> <id name="ID" column="ID"> <generator class="native"/> </id> <version name="Version" column="Version"/> <many-to-one name="Kunde" column="KundeID" c...

NHibernate eager loading one-to-many

Hi In the mapping-file I've defined a bag for Positionen. <class name="Animag.DomainModels.Models.Abrechnung, Animag.DomainModels" table="Abrechnungen" lazy="true"> <id name="ID" column="ID"> <generator class="native"/> </id> <version name="Version" column="Version"/> <many-to-one name="Kunde" column="KundeID" c...