eager-loading

Entity Framework 4.1 eager loading - on abstract classes

房东的猫 提交于 2019-12-05 07:10:13
问题 I'm using EF 4.1 at Code First approach. I have an abstract class: public abstract class Base { } And two dereived classes: public Class Derived1 : Base { public Division division{ get; set; } } public Class Derived2 : Base { public Brand brand{ get; set; } } At last, I have a query that selects a list of the Base class, and i want to perform eager loading, but i don't know who my derived classes are: using (var db = new MyContext()) { var lst = db.Base.Include(WHAT SHOULD I WRITE HERE)

How addSelect() Builder method works in Laravel

老子叫甜甜 提交于 2019-12-05 07:01:57
Say I have these models: User Model namespace App; use Illuminate\Database\Eloquent\Model; class User extends Model { /** * The table associated with the model. * * @var string */ protected $table = 'User'; protected $fillable = [ 'username', 'favoriteColor' ]; public function flights() { return $this->hasMany('App\Flight'); } } Flight Model namespace App; use Illuminate\Database\Eloquent\Model; class Flight extends Model { /** * The table associated with the model. * * @var string */ protected $table = 'Flight'; protected $fillable = [ 'flightName', ]; } I'm trying to do something with eager

Querying Relationship Existence using multiple MySQL database connections in Laravel 5.2

自闭症网瘾萝莉.ら 提交于 2019-12-05 06:06:19
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->belongsTo(Employee::class); } } The Employee model references a table employees that exists in database

NHibernate: How to perform eager subselect fetching of many children & grandchildren (object graph) in a single round-trip to the database?

筅森魡賤 提交于 2019-12-04 23:46:46
First, please don't try to argue me out of doing the eager load - traversing the object graph and causing (by lazy loading) even more than ONE round-trip to the database is just not an option. I have a big object graph. I want to fetch the root object, plus a subset of its children, grandchildren, great-grandchildren, etc. Currently I do this by creating multiple Future objects (with Criteria) and in each one, I do SetFetchMode("...", FetchMode.Eager) - see Ayende's post and Sam's 3rd comment here . There are two problems: NHibernate performs multiple select queries in the same round-trip -

Laravel 4 eager loading and categories, subcategories, articles

微笑、不失礼 提交于 2019-12-04 20:42:39
Hi i thought i can handle this myself, but actually i don't know how to bite it. I am trying to categorise my programs. There will be only 2 levels of categories: 1 CATEGORY 2 |-Subcategory I want it to be as simple as possible. - program can belong to only one subcategory, - categories can have many subcategories, - subcategories can have many programs, Of course i would like to list all programs from subcategories, when someone choose a main category. I am also not sure about my current database tables structure and relationship in models. Tables in database: programs : id, title,

Laravel eager loading sort by relationship

℡╲_俬逩灬. 提交于 2019-12-04 19:29:27
I have some relationships (that i can hopefully explain correctly) and need to sort the output by what is essentially a distant relation. I have a pivot table that contains details for many of the relations, including that that i want to sort by. --User.php public function players() { return $this->belongsToMany('App\Models\Player', 'league_player_user')->withPivot('position_id'); } --Player.php public function position() { return $this->belongsToMany('App\Models\Position', 'league_player_user'); } I will be eager loading the relationship like so; $user = User::with('players')->where('id',

Entity Framework - eager loading of related entities

青春壹個敷衍的年華 提交于 2019-12-04 18:49:06
问题 Sorry the title isn't more specific - I didn't know how to describe this succinctly. I have Trips and Location that have a many-to-many relationship - straightforward except that Locations have no need to know about the Trips that use them. I've created these entities to represent this: public class Trip { public int TripId { get; set; } public virtual IList<TripLocation> TripLocations { get; set; } } public class TripLocation { public int TripId { get; set; } public int LocationId { get; set

Entity Framework - Eager loading related entities

∥☆過路亽.° 提交于 2019-12-04 17:35:49
问题 I'm using Entity Framework 4 with MVC and need to ensure any referenced entities I want to use in my view have been loaded before the controller method returns, otherwise the view spits out the dreaded: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. When selecting straight from the context, I can just use the Include(string) method to force them to be included in the generated SQL query: var sellers = context.Sellers.Include(

How to eager load associations with the current_user?

。_饼干妹妹 提交于 2019-12-04 16:34:14
问题 I'm using Devise for authentication in my Rails app. I'd like to eager load some of a users associated models in some of my controllers. Something like this: class TeamsController < ApplicationController def show @team = Team.includes(:members).find params[:id] current_user.includes(:saved_listings) # normal controller stuff end end How can I achieve this? 回答1: I ran into the same issue and although everyone keeps saying there's no need to do this, I found that there is, just like you. So

Linq-To-Entities Include

二次信任 提交于 2019-12-04 12:39:06
I'm currently learning a bit more about Linq-To-Entities - particularly at the moment about eager and lazy loading. proxy.User.Include("Role").First(u => u.UserId == userId) This is supposed to load the User, along with any roles that user has. I have a problem, but I also have a question. It's just a simple model created to learn about L2E I was under the impression that this was designed to make things strongly type - so why do I have to write "Role"? It seems that if I changed the name of the table, then this wouldn't create a compilation error... My error is this: The specified type member