eager-loading

EntityFramework: Eager loading with excludes instead of includes?

馋奶兔 提交于 2019-12-06 04:34:55
问题 My data model has a lot of nested entities and I would like to eagerly load the whole object tree ... except for a view entities that will be explicitly loaded on demand. Using include paths I have to specify many paths and every time I add a new entity I will have to adapt those include paths. I currently use following method of my repository to load all entities of a type: public virtual IQueryable<TEntity> All(string commaSeperatedIncludePropertyPaths = "") { IQueryable<TEntity>

Eager loading with route model binding

旧巷老猫 提交于 2019-12-06 03:32:51
问题 I have a controller function like this public function show(NovelRequest $request, Novel $novel) { // load the chapters $novel->chapters; // return the detail view of a novel return view('novels.show', compact('novel')); } I receive a novel object because i m using route model binding. However, I'd like to load more than the chapters. Since it would cause many request if i now do something like $novel->chapters; $novel->bookmarks; ... I wondered if theres a way to load "multiple" relations

Loading data from associated model in same query in rails

那年仲夏 提交于 2019-12-06 00:52:23
Basically, I have a Listing model, where each listing has a country id. I need the country name in my search results view. I know I can do @listing.country.name , but this performs an extra query for each listing in my search results. I'm using Thinking Sphinx, and in my controller I have @listings = Listing.search(@ts_params).page(page_num).per(limit) I have tried adding .includes(:countries) and variations thereof but no luck. What's the best way to go about this? I want the country data to be fetched in the same query as the listings. I have exactly the same issue with listing images - it

belongs_to association loaded individually even after eager loading

五迷三道 提交于 2019-12-05 22:12:37
I have the below association class Picture < ActiveRecord::Base belongs_to :user end class User < ActiveRecord::Base has_many :pictures end And in my PicturesController i am eager loading the user class PicturesController < ApplicationController def index @pictures = Picture.includes(:user).all end end In my view, i am displaying each pictures user name -@pictures.each do |picture| %tr %td= picture.name %td= picture.user.name Now the question is, even though i am eager loading the user, i see individual queries fired while displaying the user name in the view. I have around 1000 picture

How do we load related objects (Eager Loading) in Dot Net based Azure Mobile Service?

删除回忆录丶 提交于 2019-12-05 16:20:05
If I have following model structure public class QuestionItem: EntityData { public string Content { get; set; } public bool IsAnswered { get; set; } public int NumberOfAnswers { //todo: make it computable get; set; } public UserItem By { get; set; } public string ById { get; set; } public string AtLocation { get; set; } } & parent entity as public class UserItem:EntityData { public string UserName { get; set; } public string Gender { get; set; } public string BaseLocation { get; set; } public int Age { get; set; } public int Points { get; set; } } this does generate the DB Tables with proper

Eager loading of deleted records with paranoia's default scope

早过忘川 提交于 2019-12-05 15:47:48
I'm using the paranoia gem to "soft-delete" records. Now I need to eager load these records, some of which might have been deleted, for an associated model. Paranoia adds this default_scope to the "paranoid" model: default_scope :conditions => { :deleted_at => nil } So in effect, I have these (simplified) models: class Product has_many :orders default_scope :conditions => { :deleted_at => nil } end class Order belongs_to :product end What I'm trying to achieve is to eager-load the products when accessing orders: Order.includes(:product) This (from How to use unscoped on associated relations in

Entity Framework 4 Abstract Model - How to Programatically Eager-Load Navigational Properties?

自闭症网瘾萝莉.ら 提交于 2019-12-05 15:13:44
I have an EF4 Model that is built with abstract entities/classes: Notice how State entity has a navigational property called Country . Note: I have lazy-loading disabled, so i must eager-load on demand. Now, if i have the following method: public Location FindSingle(int id) { return _repository.Find().WithId(id).SingleOrDefault(); } This does not return any associations by default. But how can i dynamically eager-load the associations when i explicitly want to? I cannot do this: return _repository.Find().WithId(id).Include("Country").SingleOrDefault(); As i am working with an abstract class

Entity Framework Eager Loading Filter

女生的网名这么多〃 提交于 2019-12-05 10:40:31
I have a simple query I want to do like this: 1) Products have ChildProducts which have PriceTiers 2) I want to get all the Products that have a Category with a ID of 1 and Display = true. 3) I want to then include all the ChildProducts that have Display = true. 4) And then include the PriceTiers that have IsActive = true. From what I have read, EF does not support Eager Loading with filters, so the following will not work: ProductRepository.Query.IncludeCollection(Function(x) x.ChildProducts.Where(Function(y) y.Display).Select(Function(z) z.PriceTiers.Where(Function(q) q.IsActive))).Where

Rails add custom eager load

为君一笑 提交于 2019-12-05 09:46:43
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 do 'id IN' query, is there a way to add back associated objects into the initial query results? For

NHibernate ThenFetchMany is retrieving duplicate children

会有一股神秘感。 提交于 2019-12-05 09:21:44
I have a parent object with a child collection containing one element, the child collection contains a "grandchild" collection containing 3 elements. I am loading the parent object from the database using NHibernate as follows Parent parentObject = session.Query<Parent>() .FetchMany(x => x.Children) .ThenFetchMany(x => x.GrandChildren) .Where(x => x.Id = "someparentid") .Single(); What I'm finding is that there are duplicate children objects (3 in total) attached to the parent object when there should be only one. (There are 3 grandchild objects correctly attached to each child.) Eager loading