eager-loading

Having troubles loading related entities (Eager Load) with ObjectContext.CreateQuery (Entity Framework and Repositories)

ⅰ亾dé卋堺 提交于 2020-01-16 02:06:27
问题 Here's a bunch of things I tried... hopefully you can extrapolate from it what I'm trying to do and what I'm doing wrong. Okay so I'm having problems with loading related entities when using this DoQuery: public ObjectQuery<E> DoQuery(ISpecification<E> where) { return (ObjectQuery<E>)_ctx.CreateQuery<E>("[" + typeof(E).Name + "]").Where(where.EvalPredicate); } If I just use this, I end up getting an object back that contains all proper parameters except the ones that are related entities...

How to count eloquent relationship without the N+1 issue and loading the entire model?

回眸只為那壹抹淺笑 提交于 2020-01-13 07:16:15
问题 I am showing a list of categories, and the article count within each category. I get the expected result, but I am having the N+1 problem. My CategoriesController index function: public function index() { return View::make('categories.index', [ 'articleCategories' => Category::where('type', 'articles')->orderBy('name')->get(), ]); } The Category model has many relationship to articles: public function articles() { return $this->hasMany('Article'); } My categories.index view: @foreach(

When must we use eager loading in NHibernate? What is it's usage?

谁说胖子不能爱 提交于 2020-01-06 11:45:14
问题 When must we use eager loading in NHibernate? What is it's usage? 回答1: One usage is when you will cache or store an object graph (in ASP.NET Cache for instance). If you don't store the whole graph, you would be missing information on a detached object. You can reattach objects of course, but that would probably be a new roundtrip to the database anyway. If you don't eager load your collections, you would need to touch every one of the to invoke the lazy fetch. In those cases, an eager fetch

When must we use eager loading in NHibernate? What is it's usage?

我怕爱的太早我们不能终老 提交于 2020-01-06 11:44:20
问题 When must we use eager loading in NHibernate? What is it's usage? 回答1: One usage is when you will cache or store an object graph (in ASP.NET Cache for instance). If you don't store the whole graph, you would be missing information on a detached object. You can reattach objects of course, but that would probably be a new roundtrip to the database anyway. If you don't eager load your collections, you would need to touch every one of the to invoke the lazy fetch. In those cases, an eager fetch

Rails 3.2.11 asset precompile fails if threadsafe! enabled

橙三吉。 提交于 2020-01-05 07:00:33
问题 I'm on Rails 3.2.11 and ruby 1.9.3.125 My app is working ok in devel and production if threadsafe! off With threadsafe! enabled I get an error during precompiling, in my asset assetsolutions.js.erb (which is the main js file of the application) I use the Workorder class as in the next line if ($('#workorder_worktype').val()=='<%= Workorder::REPAIR %>') with threadsafe! the class can't be found at precompile time, I've done some reasearch and I think it may be related with rails switching off

Rails 3.2.11 asset precompile fails if threadsafe! enabled

旧时模样 提交于 2020-01-05 07:00:13
问题 I'm on Rails 3.2.11 and ruby 1.9.3.125 My app is working ok in devel and production if threadsafe! off With threadsafe! enabled I get an error during precompiling, in my asset assetsolutions.js.erb (which is the main js file of the application) I use the Workorder class as in the next line if ($('#workorder_worktype').val()=='<%= Workorder::REPAIR %>') with threadsafe! the class can't be found at precompile time, I've done some reasearch and I think it may be related with rails switching off

How should attributes be eager loaded?

馋奶兔 提交于 2020-01-05 05:27:21
问题 I have a set of attributes/accessors on my model that are working out the number of flights for a specific aircraft type. Is there a way to only return these when I want them? If I add them to appends[] I get an N+1 problem when loading all the resources. /** * Gets the number of flights flown by the aircraft */ public function getTotalFlightsAttribute () { return Flight::whereHas('aircraft', function($query) { $query->where('aircraft_type_id', '=', $this->id); }) ->count(); } I'd like to be

Eager-loading association count with Arel (Rails 3)

纵然是瞬间 提交于 2020-01-04 02:55:26
问题 Simple task: given that an article has many comments, be able to display in a long list of articles how many comments each article has. I'm trying to work out how to preload this data with Arel. The "Complex Aggregations" section of the README file seems to discuss that type of situation, but it doesn't exactly offer sample code, nor does it offer a way to do it in two queries instead of one joined query, which is worse for performance. Given the following: class Article has_many :comments

Querying Relationship Existence using multiple MySQL database connections in Laravel 5.2

不羁岁月 提交于 2020-01-02 03:35:08
问题 I am dealing with the following situation: I have two models, an Employee with id and name fields and a Telephone with id , employee_id and flag fields. There is also an one-to-many relationship between these two models, that is an employee may have many telephones and a telephone may belong to a single employee. class Employee extends Model { public function telephones() { return $this->hasMany(Telephone::class); } } class Telephone extends Model { public function employee() { return $this-

Eager loading child and child-of-child collections in NHibernate

女生的网名这么多〃 提交于 2020-01-01 12:48:46
问题 I've got a problem with NHibernate trying to load a small hierarchy of data. My domain model looks like: class GrandParent { int ID{get;set;} IList<Parent> Parents {get; set;} } class Parent { IList<Child> Children {get; set;} } class Child { } and I would like to eager load all parents and children for a given GrandParent. This Linq-to-NH query creates the correct SQL and loads the GrandParent as expected: (the example assumes the grandparent has 2 parents who each have 2 child objects - so