eager-loading

EF4 LINQ Ordering Parent and all child collections with Eager Loading (.Include())

为君一笑 提交于 2019-11-27 14:14:30
I am doing hierarchical data binding on a grid, and I need to have the database server perform the sorting on my objects. I can easily sort the parent collection, but I can't seem to figure out how to also sort all the child collections. I have a model which has child collections nested 3 deep, and all of these collections need to be sorted. Here is a sample model of what I'm trying to accomplish: public class Year { public int Id { get; set; } public string Name { get; set; } public List<Make> Makes { get; set; } } public class Make { public int Id { get; set; } public string Name { get; set;

Loading Nested Entities / Collections with Entity Framework

瘦欲@ 提交于 2019-11-27 13:45:16
问题 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

Eager loading: The right way to do things

浪子不回头ぞ 提交于 2019-11-27 11:15:26
问题 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

Rails Eager Loading on All Finds

那年仲夏 提交于 2019-11-27 10:34:53
问题 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

org.hibernate.LazyInitializationException at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel

一世执手 提交于 2019-11-27 08:24:28
Despite of FetchType.EAGER and JOIN FETCH , I get a LazyInitalizationException while adding some objects to a @ManyToMany collection via a JSF UISelectMany component such as in my case the <p:selectManyMenu> . The @Entity IdentUser , with FetchType.EAGER : @Column(name = "EMPLOYERS") @ManyToMany(fetch = FetchType.EAGER, cascade= CascadeType.ALL) @JoinTable(name = "USER_COMPANY", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "COMPANY_ID") }) private Set<Company> employers = new HashSet<Company>(); The @Entity Company , with FetchType.EAGER :

Fetch vs FetchMany in NHibernate Linq provider

本小妞迷上赌 提交于 2019-11-27 05:20:53
问题 NHibernate eager loading can be done using Fetch and FetchMany , as described in NHibernate Linq Eager Fetching on Mike Hadlow's blog. What is the difference between these two methods and under what circumstance would each be used? 回答1: Fetch should be used for references and FetchMany for collections. This is particularly important because only FetchMany can be combined with ThenFetchMany to fetch "grandchildren" collections. Example: session.Query<User>() .FetchMany(u => u.Orders)

How do I eagerly Include the child and grandchild elements of an entity in Entity Framework Code First?

邮差的信 提交于 2019-11-27 04:27:23
问题 Imagine three entities (Customer, Book, Author) related like this: A Customer has many Books A Book has one Author I use that data to print a report like this: Customer: Peter Book: To Kill a Mockingbird - Author: Harper Lee Book: A Tale of Two Cities - Author: Charles Dickens Customer: Melanie Book: The Hobbit - Author: J. R. R. Tolkien When I query for Customers I get, as expected, a bunch of queries of the following nature A query to get the Customers A query per Customer to get his Books

Entity Framework 4.1 default eager loading

跟風遠走 提交于 2019-11-27 04:26:05
I'm using Entity Framework 4.1 code first approach. I want to make eager loading as my the dafault configuration, and by that avoid using the Include extension method in each fetching query. I did as recomended in MSDN, changing the simple lazy property at the DbContext constructor: public class EMarketContext : DbContext { public EMarketContext() { // Change the default lazy loading to eager loading this.Configuration.LazyLoadingEnabled = false; } } unfortunately, this approach is not working. I have to use the Include method to perform eager loading in each query. Any ideas why? Thanks in

Ruby on Rails: :include on a polymorphic association with submodels

ぃ、小莉子 提交于 2019-11-27 02:19:32
问题 When working with a polymorphic association, is it possible to run an include on submodels that are only present in some types? Example: class Container belongs_to :contents, :polymorphic => true end class Food has_one :container belongs_to :expiration end class Things has_one :container end In the view I'm going to want to do something like: <% c = Containers.all %> <% if c.class == Food %> <%= food.expiration %> <% end %> Therefore, I'd like to eager load the expirations when I load up c,

Eloquent eager load Order by

醉酒当歌 提交于 2019-11-27 00:40:23
I have problem with eloquent query. I am using eager loading (one to one Relationship) to get ' student ' With the ' exam ', Using the code below. Student::with('exam')->orderBy('exam.result', 'DESC')->get() And i want to order received rows by the ' result ' column in ' exam '. I am using ->orderBy('exam.result', 'DESC') But it is not working. Any ideas how to do it ? Try this: Student::with(array('exam' => function($query) { $query->orderBy('result', 'DESC'); })) ->get(); Luis Dalmolin If you need to order your students collection by the result column, you will need to join the tables.