Bright boot records in Orchard CMS

I am creating an Orchard CMS module where I want to receive download data, but cannot decide how to do it.

For example, the Client has many events, so I have ClientRecord and EventRecord for them:

public class ClientRecord { private IList<EventRecord> _eventRecords; public virtual int Id { get; set; } public virtual string Company { get; set; } public virtual IList<EventRecord> EventRecords { get { return _eventRecords ?? (_eventRecords = new List<EventRecord>()); } set { _eventRecords = value; } } } 

When I load a client into my ClientController

 var clientRecord = _clientRepository.Get(id); 

and then display "Events in my view"

  <ul> @foreach (var eventRecord in Model.EventRecords) { <li> @eventRecord.Name (@eventRecord.StartDate.ToShortDateString()) </li> } </ul> 

events are displayed, and MiniProfiler shows a separate request for lazy loading of events.

I tried to put the [Aggregate] attribute in the EventRecords collection in ClientRecord, but this had no effect.

I am not familiar with NHibernate, so hopefully this is something simple, but how can I tell if I want to load EventRecords when restoring ClientRecord?

[EDIT]

In Orchard CMS, NHibernate mappings are created for you based on the agreement that the class is called xxxRecord, and there is a database table with the same name.

So, you do not have (as far as I know) a mapping file in which you can specify this. If I am right about this, then the question is, is there a way to indicate whether you want to download the request that you use to retrieve the client (rather, like the Entity Framework), includes a "method".

+4
source share
1 answer

You must specify the load in the nHibernate file using Fluent nhibernate, it will look (something) like this:

 HasMany(x => x.EventRecords).KeyColumn("CompanyId").Not.LazyLoad().Fetch.Select(); 

Fetch.Select() will execute a second select statement to load all related event records.

Not.LazyLoad() tells nHibernate to execute this second choice immediately, if you delete this execution, it will be delayed until access to the collection is granted.

In response to your comments, you can indicate the desired download in your request, using also a selection (LINQ example is shown)

 NHSession.Query<ClientRecord>().Fetch(c => c.EventRecords).ToList(); 
+1
source

Source: https://habr.com/ru/post/1488274/


All Articles