This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I want to ask if is possible to load entities partially. Example: I load list of books (thousands) and I need just their ID and Name. Can I load just this two properties?
Thanks. |
|
|
There are a couple of ways to do this. One is field-level lazy loading: that is, you mark all fields except Name to be lazy-loaded. (You don't need to mark Id because that's always loaded.) Then when you load the collection only the Id and Name fields will be loaded. Other fields will be loaded as you access them. This is convenient if you subsequently access other fields of some of the books (e.g. accessing the CoverImage of a book when a user selects it), but requires extra configuration if you also want the option to load a whole book in one go (see named aggregates). See Querying and Performance Tuning in the help for more info. The other is to use a LINQ projection -- that is, to select only the Id and Name fields. This can be done ad hoc, without configuring lazy load patterns, but gives you "disconnected" objects, not true Book entities. For example: var bookNames = from b in unitOfWork.Books You can also project into a named type rather than an anonymous type, e.g. new BookName { Id = b.Id, Name = b.Name }, where BookName is a non-entity class. In either case, the resulting object is not an entity, is not associated with a unit of work and will not be saved if modified. Which option is appropriate to you depends on what you need -- saveable but partially populated entities, or extracted summary data that doesn't need change tracking or persistence. |
|