eager-loading

Problem with Eager Loading Nested Navigation Based on Abstract Entity (EF CTP5)

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 00:26:08
I a portion of my EF model that looks like this: Summary: Location has many Posts Post is an abstract class Discussion derives from Post Discussions have many Comments Now, the query i'm trying to achieve: Get information about Location Id 1234, including any Discussions and Comments associated with those Discussions. I can get discussions and the comments like this: var discussions = ctx.Posts .OfType<Discussion>() .Include(x => x.Comments) .ToList(); But i can't seem to get it based on the Posts navigation on the Location entity. I've tried this: var locationWithDiscussionsAndComments = ctx

Laravel Eloquent: eager loading of multiple nested relationships

家住魔仙堡 提交于 2019-11-29 00:21:56
问题 What laravel says: $books = App\Book::with('author.contacts')->get(); What I need is something like this $books = App\Book::with('author[contacts,publishers]')->get(); where we eager load multiple relationships within a relationship. Is this possible? 回答1: You can do $books = App\Book::with('author.contacts','author.publishers')->get(); 回答2: Laravel documentation on eager loading recommends listing the relationships in an array as follows: $books = App\Book::with(['author.contacts', 'author

How do I get Rails to eager load counts?

非 Y 不嫁゛ 提交于 2019-11-28 21:28:43
This is related to a question a year and change ago . I put up an example of the question that should work out of the box, provided you have sqlite3 available: https://github.com/cairo140/rails-eager-loading-counts-demo Installation instructions (for the main branch) git clone git://github.com/cairo140/rails-eager-loading-counts-demo.git cd rails-eager-loading-counts-demo rails s I have a fuller write-up in the repository, but my general question is this. How can I make Rails eager load counts in a way that minimizes db queries across the board? The n+1 problem emerges whenever you use #count

Loading Nested Entities / Collections with Entity Framework

你说的曾经没有我的故事 提交于 2019-11-28 21:21:12
I am trying to Eagerly load all the related entities or collection of Entity in one call. My Entities Looks like: Class Person { public virtual long Id { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } } Class Employee { public virtual long Id { get; set; } public DateTime AppointmentDate { get; set; } public virtual ICollection<EmployeeTitle> Titles { get; set; } public virtual Person Person { get; set; } } Class EmployeeTitle { public virtual long Id { get; set; } public virtual bool IsCurrent { get; set; } public virtual Title Title {

Eager Loading Using Fluent NHibernate/Nhibernate & Automapping

好久不见. 提交于 2019-11-28 19:17:15
I have a requirement to load a complex object called Node ...well its not that complex...it looks like follows:- A Node has a reference to EntityType which has a one to many with Property which in turn has a one to many with PorpertyListValue public class Node { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual EntityType Etype { get; set; } } public class EntityType { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList<Property> Properties { get; protected set; } public EntityType() { Properties = new List

Eager loading: The right way to do things

风流意气都作罢 提交于 2019-11-28 18:21:38
I am running Ruby on Rails 3.1. I read the following articles and documentations about eager loading and I would like to find a right way to do things: Eager Loading Associations [Official documentation] ActiveRecord::Associations::ClassMethods (see the section "Eager loading of associations") [Official documentation] Eager loading [Blog article] The #2 says: Note that using conditions like Post.includes([:author, :comments]).where(['comments.approved = ?', true]).all can have unintended consequences. The #3 says that those unintended consequences are ( note : examples are pretty the same so I

EF CTP5 - Strongly-Typed Eager Loading - How to Include Nested Navigational Properties?

a 夏天 提交于 2019-11-28 17:51:57
Attempting to cutover our EF4 solution to EF CTP5, and ran into a problem. Here's the relevant portion of the model: The pertinent relationship: - A single County has many Cities - A single City has a single State Now, i want to perform the following query: - Get all Counties in the system, and include all the Cities, and all the State's for those Cities. In EF4, i would do this: var query = ctx.Counties.Include("Cities.State"); In EF CTP5, we have a strongly typed Include, which takes an Expression<Func<TModel,TProperty>> . I can get all the Cities for the County no problem: var query = ctx

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

巧了我就是萌 提交于 2019-11-28 17:39:39
问题 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? 回答1: Let's say you have two entities with a one-to-many relationship: Customer and Order, where each Customer can have multiple Orders. When loading up a Customer

Rails Eager Loading on All Finds

谁说我不能喝 提交于 2019-11-28 17:18:17
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 Cookbook, then I eager load the recipes, and in turn the recipes eager load the :recipetags: cb = Cookbook.find(10590, :include => [:recipes]) But what I want to also do is whenever I open a recipe, have it pull in all of it's eager associations automatically - basically I want to do:

Laravel - Eager Loading Polymorphic Relation's Related Models

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 16:24:11
I can eager load polymorphic relations/models without any n+1 issues. However, if I try to access a model related to the polymorphic model, the n+1 problem appears and I can't seem to find a fix. Here is the exact setup to see it locally: 1) DB table name/data history companies products services 2) Models // History class History extends Eloquent { protected $table = 'history'; public function historable(){ return $this->morphTo(); } } // Company class Company extends Eloquent { protected $table = 'companies'; // each company has many products public function products() { return $this->hasMany