eager-loading

How to eagerly load a many to many relationship with the entity framework code first?

对着背影说爱祢 提交于 2019-12-01 07:04:40
I'll give the most basic example that I can think of for the purpose of clarity. Lets say that I have two entities of the following form: public class Student { public int Id {get;set} public string FullName {get;set;} public virtual ICollection<Course> Courses {get;set;} } public class Courses { public int Id {get;set;} public string FullName {get;set;} public virtual ICollection<Student> Students {get;set;} } Those two entities map to three tables, the third one being a table for the joins. When I query the Students like this var allStudents = context.Students; and then traverse the results

Doctrine2 eager loading runs multiple queries instead of 1

删除回忆录丶 提交于 2019-12-01 06:55:07
I'm using Symfony2 with Doctrine2 (latest versions) and have this relation defined: /** * @ORM\OneToMany(targetEntity="Field", mappedBy="event", fetch="EAGER") * @ORM\OrderBy({"name" = "ASC"}) */ protected $fields; The other side of the relation is defined as: /** * @ORM\ManyToOne(targetEntity="Event", inversedBy="fields", fetch="EAGER") * @ORM\JoinColumn(nullable=false, onDelete="CASCADE") */ protected $event; When doing a "fetchOnyById", Doctrine runs 2 queries. 1 to fetch the object itself and 1 for the related fields. I would expect this to be a join, but it isn't. When done in the

Doctrine2 eager loading runs multiple queries instead of 1

和自甴很熟 提交于 2019-12-01 05:16:56
问题 I'm using Symfony2 with Doctrine2 (latest versions) and have this relation defined: /** * @ORM\OneToMany(targetEntity="Field", mappedBy="event", fetch="EAGER") * @ORM\OrderBy({"name" = "ASC"}) */ protected $fields; The other side of the relation is defined as: /** * @ORM\ManyToOne(targetEntity="Event", inversedBy="fields", fetch="EAGER") * @ORM\JoinColumn(nullable=false, onDelete="CASCADE") */ protected $event; When doing a "fetchOnyById", Doctrine runs 2 queries. 1 to fetch the object itself

How to eagerly load a many to many relationship with the entity framework code first?

雨燕双飞 提交于 2019-12-01 04:54:07
问题 I'll give the most basic example that I can think of for the purpose of clarity. Lets say that I have two entities of the following form: public class Student { public int Id {get;set} public string FullName {get;set;} public virtual ICollection<Course> Courses {get;set;} } public class Courses { public int Id {get;set;} public string FullName {get;set;} public virtual ICollection<Student> Students {get;set;} } Those two entities map to three tables, the third one being a table for the joins.

NHibernate Eager Loading Collections + Paging

那年仲夏 提交于 2019-12-01 03:38:04
问题 Here is an example of my entities that I am trying to return with eager loaded collections. Mixes -> Tracks (collection) -> Tags (collection) I need to return a paged list of Mixes with eager loaded tracks & tags, without paging it is relativly simple by using the Future<>() function to run multiple queries for the tracks + tags. Because this data needs to be paged...how can I get all my data back so that NHibernate won't get the N+1 issue when displaying my data. Paul 回答1: Fetch the Mixes

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

青春壹個敷衍的年華 提交于 2019-11-30 19:25:49
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.ManagedBean; import javax.annotation.PostConstruct; @ApplicationScoped @ManagedBean(eager=true) public

Linq to Entities - eager loading using Include()

别说谁变了你拦得住时间么 提交于 2019-11-30 19:21:13
I've got this really basic table structure: dbo.tblCategory dbo.tblQuestion (many to one relationship to tblCategory) dbo.tblAnswer (many to one relationship to tblQuestion) So basically, what I'm trying to do is when I load a category, I want to also load all Questions, and all Answers. Now, I've been able to do this using the following code: public tblCategory Retrieve(int id) { using (var entities = Context) { var dto = (from t in entities.tblCategory.Include("tblQuestion") .Include("tblQuestion.tblAnswers") where t.Id == id select t).FirstOrDefault(); return entities.DetachObjectGraph(dto)

Laravel 5 eager loading with limit

谁说我不能喝 提交于 2019-11-30 15:12:47
问题 I have two tables, say "users" and "users_actions", where "users_actions" has an hasMany relation with users: users id | name | surname | email... actions id | id_action | id_user | log | created_at Model Users.php class Users { public function action() { return $this->hasMany('Action', 'user_id')->orderBy('created_at', 'desc'); } } Now, I want to retrieve a list of all users with their LAST action . I saw that doing Users::with('action')->get(); can easily give me the last action by simply

virtual keyword, Include extension method, lazy loading, eager loading - how does loading related objects actually work

点点圈 提交于 2019-11-30 14:20:45
Loading related object in MVC can be pretty confusing. There are lots of terms you need to be aware of and learn if you really want to know what you're doing when writing your entity model classes and controllers. A couple of questions that I've had for a very long time are: How does the virtual keyword work and when should I use it? And how does the Include extension method work and when should I use it? Here's what I'm talking about; virtual keyword: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace LazyLoading.Models { public class Brand { public

Laravel 5 eager loading with limit

谁都会走 提交于 2019-11-30 13:51:59
I have two tables, say "users" and "users_actions", where "users_actions" has an hasMany relation with users: users id | name | surname | email... actions id | id_action | id_user | log | created_at Model Users.php class Users { public function action() { return $this->hasMany('Action', 'user_id')->orderBy('created_at', 'desc'); } } Now, I want to retrieve a list of all users with their LAST action . I saw that doing Users::with('action')->get(); can easily give me the last action by simply fetching only the first result of the relation: foreach ($users as $user) { echo $user->action[0]-