eager-loading

Rails add custom eager load

我的未来我决定 提交于 2019-12-22 06:09:28
问题 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 plus a query where the 'id IN' the ids from the first query), instead of the single join query used in the past. My question is if I do a custom SQL query, then

Entity Framework 4.1 - TPT Eager Loading - “The ResultType of the specified expression is not compatible with the required type”

你离开我真会死。 提交于 2019-12-21 20:51:13
问题 I have a model with TPT inheritance. Location ( abstract ) Street ( derived from Location) GoogleStreetView ( 1 Street -> 0..1 GoogleStreetView ) Each of the above has it's own table. All was working fine until i added the "GoogleStreetView" table (which is backed by a PK/FK to Street). When i try and do this: var street = _locationRepository .Find() .OfType<Street>() .Include(x => x.GoogleStreetView) .SingleOrDefault(x => x.LocationId == 1); I get the error: The ResultType of the specified

Force eager loading of otherwise lazy loaded properties

落爺英雄遲暮 提交于 2019-12-21 03:28:05
问题 I've got a Hibernate object which's properties are all loaded lazy. Most of these properties are other Hibernate objects or PersistentSets. Now I want to force Hibernate to eager load these properties for just one time. Of course I could "touch" each of these properties with object.getSite().size() but maybe there's another way to achieve my goal. 回答1: The documentation puts it like this: You can force the usual eager fetching of properties using fetch all properties in HQL. References

how to get eager loading in a many to many relationships?

大城市里の小女人 提交于 2019-12-19 10:44:08
问题 I have a database with four tables. TableA and TableB are the main tables and the TableC is the table of the many to many relationships. TableA(IDTableA, Name...) TableB(IDTableB, Name...) TableC(IDTableA, IDTableB) This create three entities, The EntityA has an ICollection of Entity C and Entity C has a Collection of EntitiesB, so when I try to get the related entities I do this: myContext.EntityA.Include(a=>a.EntityB.Select(b=>b.EntityC)); But this throw and exception that says that the

Rails Eager Loading and where clause

故事扮演 提交于 2019-12-19 02:28:05
问题 I'm eager loading a model object with its associations: user= User.includes(:posts).find(1) But then at certain points in the code I would like to do something like this: user.posts.where(:topic => "x") But that just re-runs the query again. So instead I thought I'd do this: user.posts.select{|post| post.topic == "x" } That doesn't re-run the query. But I have a couple of questions. First, Is this the right way to do it? Second, I'm a bit confused about what select does in this case. Because

What is the equivalent of @ManagedBean(eager=true) in CDI

怎甘沉沦 提交于 2019-12-19 00:45:51
问题 As we all know that it is recommended to use annotations from javax.enterprise.context instead of javax.faces.bean as they are getting deprecated. And we all found ManagedBeans with eager="true" annotated with @ApplicationScoped from javax.faces.bean and having a @PostConstruct method are very useful to do web application initialization e.g: read properties from file system, initialize database connections, etc... Example : import javax.faces.bean.ApplicationScoped; import javax.faces.bean

Eager load associations with Active Model Serializers

泪湿孤枕 提交于 2019-12-18 11:27:17
问题 Background I have a rails application with deeply nested associations. .-< WorkPeriod Timecard -< Week -< Day -<--< Subtotal `-< Adjustment -< (has many) I'm using Active Model Serializer to build out the API. On the client side I want to load a timecard and all it's associations in one shot. Currently my serializers look like this, class TimecardSerializer < ActiveModel::Serializer embed :ids, include: true has_many :weeks end class WeekSerializer < ActiveModel::Serializer embed :ids,

Can I eager load a property using HQL?

依然范特西╮ 提交于 2019-12-18 06:48:24
问题 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 like to do this is in the query, as opposed to the mapping, if possible - as in a "join fetch..." Maybe the query would be refactored as a join and I'm having a mental

Eager loading child collection with NHibernate

老子叫甜甜 提交于 2019-12-18 04:29:17
问题 I want to load root entities and eager load all it's child collection and aggregate members. Have been trying to use the SetFetchMode in FluentNHibernate, but I am getting duplicates in one of the child collection since I have a depth of 3 levels. DistinctRootEntityResultTransformer unfortunately only removes the root duplications. return Session.CreateInvoiceBaseCriteria(query, archived) .AddOrder(new Order(query.Order, query.OrderType == OrderType.ASC)) .SetFetchMode("States", FetchMode

Rails 3 Limiting Included Objects

帅比萌擦擦* 提交于 2019-12-18 03:55:39
问题 For example I have a blog object, and that blog has many posts. I want to do eager loading of say the first blog object and include say the first 10 posts of it. Currently I would do @blogs = Blog.limit(4) and then in the view use @blogs.posts.limit(10) . I am pretty sure there is a better way to do this via an include such as Blog.include(:posts).limit(:posts=>10) . Is it just not possible to limit the number of included objects, or am I missing something basic here? 回答1: Looks like you can