Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Custom Templates> RemovedEntitiesTracker initialization
 

Pages: 1
Custom Templates
RemovedEntitiesTracker initialization
Page:1/1 

  Print all messages in this thread  
Poster Message
gilles.marceau
User



Location:

Joined on:
14-Feb-2017 11:35:46
Posted:
12 posts
# Posted on: 14-Feb-2017 11:49:06.  
Hi,

I'm actually developping a WPF application in which I use the RemovedEntitiesTracker property of EntityCollection to manage the deletion of the entities.

I would like to simplify the use of it by initialize this property automatically to be not have to check if it's null before using it.
Is there a way to do it or must I change the LLBLGEN template to generate the needed code ?
If changing the template is the only way, can you give me the place where I must put it (because I tried to put it on the constructors of the EntityCollection but it seems to not be the right way to do it).

Thanks in advance
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37476 posts
# Posted on: 14-Feb-2017 15:23:55.  
The best way to deal with this I think is to simply let the framework deal with it by using DataScopes http://www.llblgen.com/Documentation/5.1/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_datascopes.htm

Have you looked at these? There's an example as well on github: https://github.com/SolutionsDesign/LLBLGenProExamples_5.x/tree/master/Example_DataScope


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
gilles.marceau
User



Location:

Joined on:
14-Feb-2017 11:35:46
Posted:
12 posts
# Posted on: 15-Feb-2017 14:18:21.  
A lot of work has already been done at this time so it's not a possibility for me to use datascope.

Actually, the UI call "service" methods (not real services, just the name) which are intercept using AOP to create DataAccessAdapter, manage transactions, error log, performance log...

Because I fetch a graph of objects (say Order with Order details) and that Order Details can be removed, I need to be able to trace the removal to delete it on the "service" side.

In previous projects, I used to initialize RemoveedEntitiesTracker but it was not really a good stuff so I would like to improve it.
  Top
gilles.marceau
User



Location:

Joined on:
14-Feb-2017 11:35:46
Posted:
12 posts
# Posted on: 15-Feb-2017 17:03:11.  
Finally I modifiy the "commonEntityBaseAdapter.template" template to initialize the RemovedEntitiesTracker properrty like this

Code:

        protected EntityCollection<T> GetOrCreateEntityCollection<T, TFactory>(string navigatorName, bool setContainingEntityInfo, bool forMN, ref EntityCollection<T> destination)
            where T:EntityBase2 , IEntity2
        {
            if(destination==null)
            {
                destination = new EntityCollection<T>(EntityFactoryCache2.GetEntityFactory(typeof(TFactory)));
                destination.RemovedEntitiesTracker = new EntityCollection<T>(EntityFactoryCache2.GetEntityFactory(typeof(TFactory)));


and it seems to run correctly (when entity is created manually or prefteched). Is is the right place for you?


  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14484 posts
# Posted on: 15-Feb-2017 20:16:21.  
Quote:
Is is the right place for you?
I believe so
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37476 posts
# Posted on: 16-Feb-2017 10:09:22.  
If the generated method is the same for all entities, you can simply extend commonEntityBase with a partial class and add the method there, no need for extra templates

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
gilles.marceau
User



Location:

Joined on:
14-Feb-2017 11:35:46
Posted:
12 posts
# Posted on: 16-Feb-2017 10:35:00.  
Don't understand.
Because I want this behavior to be by default, and that GetOrCreateEntityCollection is the method called by the framework, I must find a way to change this method.

And I can't redefine this method in the partial class, can I ?
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37476 posts
# Posted on: 16-Feb-2017 10:57:32.  
oh sorry, my bad! Embarrassed I hadn't looked into the code and was assuming that was your method. I don't remember every method in the framework Wink

I do recall there's another way though. I'll look into it.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37476 posts
# Posted on: 16-Feb-2017 11:08:05.  
Yes there's another way which doesn't require template editing Regular Smiley

Create a partial class of HelperClasses\EntityCollection.cs.

In there, override the following method like this:
Code:

protected override void PlaceInRemovedEntitiesTracker(TEntity item)
{
    if(this.RemovedEntitiesTracker == null)
    {
        this.RemovedEntitiesTracker = new EntityCollection<TEntity>();
    }
    base.PlaceInRemovedEntitiesTracker(item);
}



This will make sure that when the removedentitiestracker is needed, there's one, and if it's not needed, none is created. The base class' method will check if there's a tracker and return if there's none. So this is IMHO the best way: when you need it, you'll get a call to that method, you create the tracker if it's not there, and then proceed as normal.
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
gilles.marceau
User



Location:

Joined on:
14-Feb-2017 11:35:46
Posted:
12 posts
# Posted on: 16-Feb-2017 16:37:15.  
OK I understand.
Unfortunately, I prefer change the template because I would have to write code like this to check if RemovedEntitiesTracker is null before iterate it.

Code:
if (order.OrderDetails.RemovedEntitiesTracker != null)
{
     foreach (OrderDetailEntity orderDetail in order.OrderDetails.RemovedEntitiesTracker)
     {
     }
}


Thanks


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.