Deleting entities in a hierachy

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 18-Apr-2012 14:03:24   

I was trying to clear all rows from a multi-level hierarchy with these types of statements:

            adapter.DeleteEntitiesDirectly(typeof(PersonEntity), null);
            adapter.DeleteEntitiesDirectly(typeof(LegalBodyEntity), null);

and came across the "No parameterless constructor defined for this object" on the abstract root entity.

I saw your reply in an old 2008 post about Activator.CreateInstance.

There is an overload with a bool that allows use of nonpublic ctors which would solve this problem.

Cheers Simon

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 18-Apr-2012 14:06:36   

(Of course the string overload version works too for now)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Apr-2012 15:04:41   

(Of course the string overload version works too for now)

Should we consider this solved? simple_smile

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 18-Apr-2012 16:31:18   

Walaa wrote:

(Of course the string overload version works too for now)

Should we consider this solved? simple_smile

Well that's up to you of course. simple_smile

However, personally, I don't like hard-coding strings in code and since the generated code doesn't provide a constant, I would prefer to be able to use the overload with Type for which I have provided a solution which should just work.

Then again, I also prefer generic methods and optional parameters, so I actually prefer

public virtual void DeleteEntitiesDirectly<T>(IRelationPredicateBucket filterBucket = null) where T: CommonBaseEntity

making my code

adapter.DeleteEntitiesDirectly<LegalBodyEntity>();

stuck_out_tongue_winking_eye

Incidentally, why aren't optional parameter used? They would make code a lot cleaner.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Apr-2012 17:01:59   
EntityType.LegalBodyEntity.ToString();

This will get you the string name, without hardcoding strings simple_smile

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 19-Apr-2012 08:19:56   

Walaa wrote:

EntityType.LegalBodyEntity.ToString();

This will get you the string name, without hardcoding strings simple_smile

Ok, fair enough - I missed that one. smile

However, I override ToString() in the base entity class so that it displays the entity ID etc. Will add a property calling base.ToString(). Thanks.