How to set a field to null in a hierachy

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 18-Sep-2012 12:36:58   

I have LegalBody at the top of a hierarchy (or bottom depending on how you look at it). One of its fields DefaultAddressID is a nullable FK to Address.

I want simple to set that field to null for all entities in the hierarchy so that I can clear the Address table (Clearing the LegalBody table first is not an option)

All the LegalBodyEntity ctors are internal so I can't use UpdateEntityDirectly. What other method can I use?

Cheers Simon

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 18-Sep-2012 12:44:17   

Well this works smile but there must be a better way!


                var ctor = typeof(LegalBodyEntity).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, CallingConventions.Standard, new Type[0], null);
                var allLegalBodies = (LegalBodyEntity) ctor.Invoke(null);
                allLegalBodies.DefaultAddressID = null;
                adapter.UpdateEntitiesDirectly(allLegalBodies, null);

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 18-Sep-2012 16:30:02   

The ctor is internal because you marked it as abstract. You can create an instance through the factory though. var legalBodiesEntity = new LegalBodyFactory().Create();

etc. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 18-Sep-2012 18:03:35   

OK, but why are these type-specific factories returning interfaces rather than properly typed objects?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Sep-2012 20:10:49   

For polymorphism I suppose. simple_smile