eager-loading

Linq to Entities - eager loading using Include()

核能气质少年 提交于 2019-11-30 03:02:54
问题 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(

Entity Framework - what's the difference between using Include/eager loading and lazy loading?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 21:49:00
I've been trying to familiarize myself with the Entity Framework. Most of it seems straight forward, but I'm a bit confused on the difference between eager loading with the Include method and default lazy loading. Both seem like they load related entities, so on the surface it looks like they do the same thing. What am I missing? Let's say you have two entities with a one-to-many relationship: Customer and Order, where each Customer can have multiple Orders. When loading up a Customer entity, Entity Framework allows you to either eager load or lazy load the Customer's Orders collection. If you

Rails Eager Load and Limit

寵の児 提交于 2019-11-29 10:36:50
I think I need something akin to a rails eager loaded query with a limit on it but I am having trouble finding a solution for that. For the sake of simplicity, let us say that there will never be more than 30 Person s in the system (so Person.all is a small dataset) but each person will have upwards of 2000 comments (so Person.include(:comments) would be a large data set). Parent association class Person < ActiveRecord::Base has_many :comments end Child association class Comment < ActiveRecord::Base belongs_to :person end I need to query for a list of Person s and include their comments , but

FindAll with includes involving a complicated many-to-(many-to-many) relationship (sequelizejs)

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 10:26:13
问题 This has a sibling question in Software Engineering SE. Consider Company , Product and Person . There is a many-to-many relationship between Company and Product , through a junction table Company_Product , because a given company may produce more than one product (such as "car" and "bicycle"), but also a given product, such as "car", can be produced by multiple companies. In the junction table Company_Product there is an extra field "price" which is the price in which the given company sells

Eager loading in EntityFramework with DbContext.Database.SqlQuery

≡放荡痞女 提交于 2019-11-29 10:06:12
In EF 4, can I do eager loading of navigation properties by writing sql on DbContext.Database.SqlQuery or DbContext.Set<T>().SqlQuery ? I don't seem to be getting my navigation properties populated. Edit It seems I can do eagerloading with DbContext.Set().SqlQuery, just not DbContext.Database.SqlQuery. Any idea why? DbSet.SqlQuery works differently than Database.SqlQuery. The method on DbSet applies to the given entity set. It has to return entities of the given type and by default the returned entities will be tracked. Database.SqlQuery can return any object (possibly not an entity) and the

EF: Lazy loading, eager loading, and “enumerating the enumerable”

给你一囗甜甜゛ 提交于 2019-11-29 06:07:32
问题 I find I'm confused about lazy loading, etc. First, are these two statements equivalent: (1) Lazy loading: _flaggedDates = context.FlaggedDates.Include("scheduledSchools") .Include ("interviews").Include("partialDayAvailableBlocks") .Include("visit").Include("events"); (2) Eager loading: _flaggedDates = context.FlaggedDates; In other words, in (1) the "Includes" cause the navigation collections/properties to be loaded along with the specific collection requested, regardless of the fact that

NHibernate: Why does Linq First() force only one item in all child and grandchild collections with FetchMany()

孤街浪徒 提交于 2019-11-29 05:46:43
Domain Model I've got a canonical Domain of a Customer with many Orders , with each Order having many OrderItems : Customer public class Customer { public Customer() { Orders = new HashSet<Order>(); } public virtual int Id {get;set;} public virtual ICollection<Order> Orders {get;set;} } Order public class Order { public Order() { Items = new HashSet<OrderItem>(); } public virtual int Id {get;set;} public virtual Customer Customer {get;set;} } OrderItems public class OrderItem { public virtual int Id {get;set;} public virtual Order Order {get;set;} } Problem Whether mapped with FluentNHibernate

Eager loading child collection with NHibernate

限于喜欢 提交于 2019-11-29 05:28:32
I want to load root entities and eager load all it's child collection and aggregate members. Have been trying to use the SetFetchMode in FluentNHibernate, but I am getting duplicates in one of the child collection since I have a depth of 3 levels. DistinctRootEntityResultTransformer unfortunately only removes the root duplications. return Session.CreateInvoiceBaseCriteria(query, archived) .AddOrder(new Order(query.Order, query.OrderType == OrderType.ASC)) .SetFetchMode("States", FetchMode.Eager) .SetFetchMode("Attestations", FetchMode.Eager) .SetFetchMode("AttestationRequests", FetchMode.Eager

Rails 3 Limiting Included Objects

谁都会走 提交于 2019-11-29 03:20:46
For example I have a blog object, and that blog has many posts. I want to do eager loading of say the first blog object and include say the first 10 posts of it. Currently I would do @blogs = Blog.limit(4) and then in the view use @blogs.posts.limit(10) . I am pretty sure there is a better way to do this via an include such as Blog.include(:posts).limit(:posts=>10) . Is it just not possible to limit the number of included objects, or am I missing something basic here? Looks like you can't apply a limit to :has_many when eager loading associations for multiple records. Example: class Blog <

Serialize Entity Framework object with children to XML file

六眼飞鱼酱① 提交于 2019-11-29 02:30:59
I'm querying data with parent/child result sets using Entity Framework and I want to export this data to an XML document. var agreement = storeops.Agreements.SingleOrDefault(a => a.AgreementNumber == AgreementTextBox.Text); XmlSerializer serializer = new XmlSerializer(agreement.GetType()); XmlWriter writer = XmlWriter.Create("Agreement.xml"); serializer.Serialize(writer, agreement); This works well except it only serializes the parent without including the related child records in the XML. How can I get the children to serialize as well? I also tried using POCO generated code and the child