Problem with "inMemory" Entities

Posts   
 
    
Torsten
User
Posts: 26
Joined: 13-Mar-2015
# Posted on: 01-Feb-2016 11:00:01   

Hi there,

we are facing a problem with some entities we want to load only once on start. We are using LLBLgen 4.2.15 with adapter.

I try to make it clear:

We have a lot tables in db which contains "system-data" e.g. paymenttypes, countries or shoptype.

Because we need these entities a lot of times in our application, we only want to load these entities at startup.

We also have entities which have a foreign-key to this entities. Lets say: OrderHeader has a countryid and a paymenttypeid field.

Now, because we dont now exactly if we need the country when working with orderheader we fetch it without prefetchpath.

So, if the user want to do any work on the header entity, we set the foreignkey entities on demand, like this:


If pHeader.Country Is Nothing Then
                    pHeader.Country= GlobalCache.Get(Of SystemCountryEntity)()(pHeader.CountryId.Value)
End If

On first call after application start everything works fine. Now the user load the header entity once again, because something changed in db and/or he wants to do the function again.

Now, the code above dont work and the pHeader.Country is nothing after setting it. It seems that the CountryEntity has a collection auf HeaderEntities and thinks, that nothing changed, so nothing has to be done.

So:

Is it possible to load/set the CountryEntity so it can added multiple times to the HeaderEntity?

Hopefully I could make it clear what I want to do and there is a solution for that.

Regards

Torsten

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 01-Feb-2016 20:10:12   

Do you have a Navigator: Country.HeaderEntities? If, yes, do you want it, or can you get rid of it?

Torsten
User
Posts: 26
Joined: 13-Mar-2015
# Posted on: 02-Feb-2016 10:59:54   

No, we dont need to navigate through Country.HeaderEntities.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 02-Feb-2016 23:37:16   

It seems that the CountryEntity has a collection auf HeaderEntities and thinks, that nothing changed

Could you please double check?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-Feb-2016 08:36:17   

What you could do is delete the navigator on the Country side in the designer, so the relationship OrderHeader - Country has two navigators, one on the OrderHeader side, and one on the Country side. Remove the one on the Country side (the PK side). This means 'Country' won't have an OrderHeader collection.

Additionally, you could also set the FK field in OrderHeader instead of the 'Country' property.

Frans Bouma | Lead developer LLBLGen Pro
Torsten
User
Posts: 26
Joined: 13-Mar-2015
# Posted on: 04-Feb-2016 15:11:12   

For only one Entity it would be possible to remove the navigator in designer.

But, first of all, we dont use the designer very often because we have written some batch files which start the CLIs.

And: its a dynamic cache, where the developer could place any entity he wants. So it has to work for many entities.

@Walaa: we checked more then double, it is everytime the same issue: at first time it works fine, after thtat the property stays nothing.

It is not applicable to set only the FK field, because maybe Country has a flag which is important for the functions. We only need the full entity for these flags.

The best way to solve the problem would be while loading the entities into the cache to mark them as only "one way entity". I hope this is possible anyway.

Or is there a way to clear the FK Entities in CountryEntity when accessing it?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Feb-2016 18:05:21   

If you are not Saving the ConutryEntity at any point of time, you can first look for the Header entity in the Country.headerENtities collection first and remove it if it does exist, before re-assigning it.

Torsten
User
Posts: 26
Joined: 13-Mar-2015
# Posted on: 05-Feb-2016 14:54:01   

Where would be the best central (generic) place to do this?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Feb-2016 03:34:32   

Torsten wrote:

Where would be the best central (generic) place to do this?

Ideally it would be inside

GlobalCache.Get(...)

BTW, Are you aware of Resulset Caching?

David Elizondo | LLBLGen Support Team