eager-loading

Symfony/doctrine: Optimize n+1 queries

怎甘沉沦 提交于 2019-12-11 04:07:12
问题 Context Imagine a set of proposals, where every user can vote up or down for a proposal. So I have 2 models: A Proposal , A Vote , related to a proposal , a user , and an opinion (up or down). Now I want to display all my proposals, including extra information for each proposal: How many upvotes ? How many downvotes ? Has the current user upvoted ? Has the current user downvoted ? Issue This is really easy to implement, but this implies 4 request per proposal display (called the n+1 query

Entity framework 'include' including more than it should

荒凉一梦 提交于 2019-12-11 03:35:39
问题 I have a class Program: [Table("Program")] public class Program { [Key] public long ProgramId { get; set; } public string Name { get; set; } public string Description { get; set; } public bool IsActive { get; set; } public virtual ICollection<Activity> Activities { get; set; } public virtual ICollection<User> Users { get; set; } public virtual ICollection<TimeEntry> TimeEntries { get; set; } } The typical usage pattern is to grab a Program and all it's associated Activities . Much less often

How can I Include Multiples Tables in my linq to entities eager loading using mvc4 C#

醉酒当歌 提交于 2019-12-11 03:03:41
问题 I have 6 classes and I try to use linq to Entities to get the SiglaUF information of the last deeper table (in the view - MVC). The problem is I receive the following error: "The ObjectContext instance has been disposed and can no longer be used for operations that require a connection." The view is like that: > @model IEnumerable<DiskPizzaDelivery.Models.EnderecoCliente> > @foreach (var item in Model) { > @Html.DisplayFor(modelItem => item.CEP.Cidade.UF.SiglaUF) > } The query that i use: var

Bound FetchMany in Linq to NHibernate

*爱你&永不变心* 提交于 2019-12-11 01:55:28
问题 I am using FetchMany for some of my queries and the NHibernate profiler gives me the following error: WARN: firstResult/maxResults specified with collection fetch; applying in memory! I guess this is because the fetch is unbound. Is there a solution to this? 回答1: This problem arises because using FetchMany will bring the whole result set to memory and then Take the specified subset (something inefficient and potentially dangerous). Apparently there is no way to limit the subset before

Why doesn't this Include work?

北慕城南 提交于 2019-12-11 01:45:11
问题 I am passing values into a method which uses a foreach loop to iterate through a collection. In the loop, an Include statement is used from entity framework to eager load. This is what I pass in: var exp = new Collection<Expression<Func<Foo,object>>>(); Why is it that when I use this: exp.Add(f => f.Bars.Select(b=> b.Employees.Select( e=> e.Position))); exp.Add(f => f.Bars.Select(b=> b.Employees.Select( e=> e.Bank))); and Employee, Position, and Bank all have the field Name that it will

EF Code first Eager loading and OrderBy problem

╄→尐↘猪︶ㄣ 提交于 2019-12-11 01:43:35
问题 I have two entities called Category and Product with 1:n relation. I want to get a Category with its childs that childs be in order. This is my linq: _db.Categories.Where(c => c.CategoryID == catID) .Include(c => c.Products.OrderBy(p => p.ProductID)) .SingleOrDefault(); This query enforce with the below exception because of orderby. The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator

How to use Eager Loading and Join in Eloquent at a same time in laravel 4

痴心易碎 提交于 2019-12-11 01:09:30
问题 Models class WPModel extends Eloquent { protected $table = 'work_processes'; protected $guarded = array('id'); protected $softDelete = true; // declaring one-to-many relationship public function relatedWPAQs() { return $this->hasMany('WPAQModel', 'wp_id'); } public function relatedUsers() { return $this->belongsTo('UserModel', 'wp_owner_id'); } } class UserModel extends Eloquent { protected $table = 'users'; protected $softDelete = true; public function relatedWPs() { return $this->hasMany(

Entity framework many-to-many relation table created “backwards”

随声附和 提交于 2019-12-10 15:12:15
问题 I'm having an issue with EF6 and many-to-many relations. I have a following setup: public class Foo { public int Id { get; set; } public virtual ICollection<Bar> Bars { get; set; } public virtual ICollection<SubBar> SubBars { get; set; } public Foo() { Bars = new HashSet<Bar>(); SubBars = new HashSet<SubBar>(); } } public class Bar { public int Id { get; set; } public virtual ICollection<Foo> Foos { get; set; } public Bar() { Foos = new HashSet<Foo>(); } } public class SubBar { public int Id

Eager-load the whole object-graph at runtime in Hibernate

半城伤御伤魂 提交于 2019-12-10 15:04:32
问题 Please read on before saying anything along the lines of "specify the fetch type in the query". That's not what I'm after. I'm looking for a way to eager-load a complete object-graph (the object + all its children and all their children and so on). I do not want to enumerate all properties that are to be loaded. I don't know them until runtime. N+1 queries aren't a problem. But at the end of this magical operation, I don't want a single proxy or lazy collection left in my graph. It should be

Injecting @EJB in OmniFaces @Eager bean causes “Severe: No valid EE environment for injection of org.omnifaces.cdi.eager.EagerBeansRepository”

 ̄綄美尐妖づ 提交于 2019-12-10 14:54:33
问题 Using @ApplicationScoped @Named @Eager , my @EJB -injected @Stateless beans are not properly instantiated and evaluate to null . I had an @ApplicationScoped @ManagedBean(eager=true) that was used to schedule a few jobs. Some @Stateless beans were injected using @EJB annotation, and that worked fine. In the move to CDI annotations, I added the OmniFaces @Eager annotation as substitute for @ManagedBean(eager=true) which is missing in standard CDI: import javax.annotation.PostConstruct; import