eager-loading

EF4 and undesired loading of related collection with AddObject

我是研究僧i 提交于 2019-11-28 09:26:49
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)filterContext.RouteData.Values["action"], Controller = filterContext.Controller.GetType().Name, DateAdded =

Ruby on Rails: :include on a polymorphic association with submodels

喜欢而已 提交于 2019-11-28 08:34:49
When working with a polymorphic association, is it possible to run an include on submodels that are only present in some types? Example: class Container belongs_to :contents, :polymorphic => true end class Food has_one :container belongs_to :expiration end class Things has_one :container end In the view I'm going to want to do something like: <% c = Containers.all %> <% if c.class == Food %> <%= food.expiration %> <% end %> Therefore, I'd like to eager load the expirations when I load up c, because I know I will need every last one of them. Is there any way to do so? Just defining a regular

Fetch vs FetchMany in NHibernate Linq provider

落花浮王杯 提交于 2019-11-28 04:27:09
NHibernate eager loading can be done using Fetch and FetchMany , as described in NHibernate Linq Eager Fetching on Mike Hadlow's blog. What is the difference between these two methods and under what circumstance would each be used? Fetch should be used for references and FetchMany for collections. This is particularly important because only FetchMany can be combined with ThenFetchMany to fetch "grandchildren" collections. Example: session.Query<User>() .FetchMany(u => u.Orders) .ThenFetchMany(o => o.OrderItems) 来源: https://stackoverflow.com/questions/4394692/fetch-vs-fetchmany-in-nhibernate

Rails Eager Load and Limit

我只是一个虾纸丫 提交于 2019-11-28 03:54:57
问题 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 <

Eager loading in EntityFramework with DbContext.Database.SqlQuery

大憨熊 提交于 2019-11-28 03:31:53
问题 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? 回答1: 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

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

末鹿安然 提交于 2019-11-27 23:24:25
问题 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

Eager Loading Using Fluent NHibernate/Nhibernate & Automapping

杀马特。学长 韩版系。学妹 提交于 2019-11-27 20:32:39
问题 I have a requirement to load a complex object called Node ...well its not that complex...it looks like follows:- A Node has a reference to EntityType which has a one to many with Property which in turn has a one to many with PorpertyListValue public class Node { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual EntityType Etype { get; set; } } public class EntityType { public virtual int Id { get; set; } public virtual string Name { get; set; } public

How do I eagerly Include the child and grandchild elements of an entity in Entity Framework Code First?

醉酒当歌 提交于 2019-11-27 20:21:08
Imagine three entities (Customer, Book, Author) related like this: A Customer has many Books A Book has one Author I use that data to print a report like this: Customer: Peter Book: To Kill a Mockingbird - Author: Harper Lee Book: A Tale of Two Cities - Author: Charles Dickens Customer: Melanie Book: The Hobbit - Author: J. R. R. Tolkien When I query for Customers I get, as expected, a bunch of queries of the following nature A query to get the Customers A query per Customer to get his Books A query per Book to get its author I can reduce the number of queries by including the books like so:

Serialize Entity Framework object with children to XML file

瘦欲@ 提交于 2019-11-27 16:52:43
问题 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.

Problem with Eager Loading Nested Navigation Based on Abstract Entity (EF CTP5)

▼魔方 西西 提交于 2019-11-27 15:18:38
问题 I a portion of my EF model that looks like this: Summary: Location has many Posts Post is an abstract class Discussion derives from Post Discussions have many Comments Now, the query i'm trying to achieve: Get information about Location Id 1234, including any Discussions and Comments associated with those Discussions. I can get discussions and the comments like this: var discussions = ctx.Posts .OfType<Discussion>() .Include(x => x.Comments) .ToList(); But i can't seem to get it based on the