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
|
Hello,
I'm converting an existing application which uses NHibernate, to use LS. There are a couple of questions I have: 1- when using Linq2NH, we could eagerly load a collection / reference like this: var queryable = UnitOfWork.CurrentSession.Linq<Purchase>(); is there any equivalance of this on LS?
2- When creating an entity, not using the designer, is there a way not to inherit from Entity or Entity<T> (possibly just by implementing an interface)? do you support (or plan to) persistence ignorance scenario where it should not be mandatory to inherit from any base class. Thanks for the great product. |
|
|
1. Eager loading is set up in the model, not in the query. If you are writing the classes by hand, apply the [EagerLoad] attribute to the association; if using the the designer, set the Eager Load Collection and/or Eager Load Backreference flags. This causes the association always to be eager loaded. Sometimes you need to be able to control whether a given association gets eager loaded or not. To do this, use a named aggregate. Again, these are set up on the model -- basically for each association you can specify which aggregates cause it to eager load (for example, a Building entity might make its Residents part of an "EmployeePlanning" aggregate, its Furniture part of an "Assets" aggregate, and its CoffeeMachines part of both). To specify that a given aggregate should be eager-loaded in a given query, specify Query.AggregateName (core API) or use the WithAggregate operator (LINQ). See Help Topics > LightSpeed > Querying and Help Topics > LINQ > Using LightSpeed Features From LINQ. E.g. uow.Buildings.WithAggregate("Furniture"). 2. No. LightSpeed requires inheritance from Entity<T>: this is a framework requirement, not a designer requirement. We are aware that persistence ignorance is something that several customers are interested in but because of the major architectural impact it's not something we expect to offer in the immediate future. |
|
|
I understand. So, you should name the aggregates on the model, in order to load them using WithAggregates extension method, but how about loading some arbitrary collection / reference using the already existing "Backreference Name" / "Collection Name", something like this: var query = from sales in uow.Purchases query.LoadWith(x => x.Product) or probably easier using names directly: query.LoadWith("Product") |
|
|
It kind of does the same thing, but (as discussed on another thread) it reflects a different approach: ad hoc eager loading based on the query site's specialised knowledge of its own requirements vs. standard reusable aggregates that arise from the domain analysis. Marking up relations isn't just a burden for the sake of being burdensome: it does add value when you're able to reuse the aggregates! Anyway, I agree there's value in offering both, and have logged a feature request for ad hoc eager loading. Let us know how much of priority this is for you. |
|
|
Thanks for considering this. I think data-driven applications (comparing to domain-driven) will benefit from ad-hoc eager loading feature. The prio for me is medium-low because of existing eager load option on the model designer. |
|