eager-loading

How do I get Rails to eager load counts?

三世轮回 提交于 2019-12-17 23:46:58
问题 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

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

…衆ロ難τιáo~ 提交于 2019-12-17 22:14:21
问题 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

EF4 and undesired loading of related collection with AddObject

China☆狼群 提交于 2019-12-17 18:58:51
问题 I have an odd case where adding a record is causing unwanted loading of a related collection. For example, I have Requests and Sessions. A Session can contain many Requests. I already have loaded the session, and just want to add a new request. However, when I set call AddObject on the ObjectSet of the Request repository, SQL Profiler shows a select query getting executed on all related requests on that session. Here is the problem code: this._request = new Request { Action = (string

Explicit loading of multiple references/collections on entity

孤人 提交于 2019-12-14 03:46:39
问题 Consider following entity model: public class Parent { public virtual FirstChild FirstChild { get; set; } public virtual SecondChild SecondChild { get; set; } } In my code, I have loaded Parent entity: Parent parent = <loaded in some way>; To explicitly load its navigational properties, I use db.Entry(parent).Reference(p => p.FirstChild).Load(); db.Entry(parent).Reference(p => p.SecondChild).Load(); But this results in two DB queries. Question: is there a more elegant way, that would allow to

Laravel eager loading count relation

此生再无相见时 提交于 2019-12-14 02:12:39
问题 I have three models, Order, OrderProduct and Product. OrderProduct is the table that create the relation from Order and Product that stores information like price or quantity. In my product list action i need to show how many orders are open (pending or paid) for each product. So i'm trying to eager load this relation like this: // ProductController.php public function index() { $data = Product::with(['reservedStock']); return $data; } And //Product.php public function reservedStock() {

Disable all lazy loading or force eager loading for a LINQ context

老子叫甜甜 提交于 2019-12-13 11:53:52
问题 I have a document generator which contains queries for about 200 items at the moment but will likely be upwards of 500 when complete. I've recently noticed that some of the mappings denote lazy loading. This presents a problem for the document generator as it needs access to all of these properties based on which document is being generated. While I am aware of the DataLoadOptions that can be specified to the context, this would result in me having to explicitly specify every column that

Navigating through relations on two paths in schema

Deadly 提交于 2019-12-13 08:47:06
问题 From top to bottom I have the belongs_to relationship between my tables , and well has_many from the other direction. ReportTarget Report Manager Organization and Score Manager Organization so notice that Report table and Score table are kind of on the same level. They both have Manager Table as their parent. Individually I could figure out how to navigate them with eager loading. For first one I will do: @blah = Organization.includes(managers: { reports: :report_targets }).find(params[:id])

Laravel 4 automatically create relationships in BaseModel - using “with”-array or scopes or what?

こ雲淡風輕ζ 提交于 2019-12-13 05:06:41
问题 I have successfully created a few relations in a Model. This is the user-model <?php class User extends BaseModel{ protected $table = 'users'; public function group(){ return $this -> belongsTo('UserGroup'); } ... } ?> and this is the UserGroup-model (UserGroup.php) <?php class UserGroup extends BaseModel{ ... } ?> Every user can be in one group (the database-column is called 'group_id' in the users-table). If I want to do eager loading on this relation, it works perfectly fine, also for

Eager load hasMany & belongsTo (circular reference/infinite loop)

北慕城南 提交于 2019-12-12 20:49:41
问题 UPDATE (SOLUTION) If you need ->user relationship from one of the $image inside $user->images , then $user variable is already available cause you loaded the ->images from it! Don't use protected $with Eloquent property. It's an anti-pattern. Instead explicitly eager load relationships on-demand from where/when it's needed ( Note : it should not prevent you to keep things DRY!) If you really need/want to, see @nicksonyap answer. It does the trick (I believe – not tested). ORIGINAL I'm running

How to map LINQ To SQL to enable eager loading, return EntitySet or ICollection?

大兔子大兔子 提交于 2019-12-12 15:26:59
问题 This is related (but fairly independent) to my question here: Why SELECT N + 1 with no foreign keys and LINQ? I've tried using DataLoadOptions to force eager loading, but I'm not getting it to work. I'm manually writing my LinqToSQL mappings and was first following this tutorial: http://www.codeproject.com/Articles/43025/A-LINQ-Tutorial-Mapping-Tables-to-Objects Now I've found this tutorial: http://msdn.microsoft.com/en-us/library/bb386950.aspx There's at least one major difference that I can