Inheritance of common fields.

Posts   
 
    
A.Alamo
User
Posts: 12
Joined: 12-Aug-2011
# Posted on: 12-Aug-2011 15:16:02   

Hi, I have a model that requires some fields to exist in every entity on the model, fields like IsDeleted, LastModifyDate ... So i tough the best way would be to create a base entity with those fields and make any entity to inherit from it in target-per-entity form.

That gets the job done but i have some doubts about how will that affect performance on the database, because every record i create in a table would create another one in the base entity table.

Anyone has done something similar?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Aug-2011 20:13:45   

Hi there,

Are those fields (LastModifyDate, IsDeleted) are actually database columns for every table? I think inheritance isn't for this. All depends on what you want to achieve and how is your Database model.

For instance, suppose you have 3 tables: Order, OrderDetail, Customer. All of that tables have columns LasModifyDate and IsDeleted. When you create your LLBLGen project (DB-first. But you also can create it from model-first) you will have three entities Order, OrderDetail and Customer, all have fields LasModifyDate and IsDeleted. But what is what you want to achieve?

Suppose you want to refactor those common fields, you could create a ValueType with those fields and name it "AuditInfo", then assign that type to refactor the fields in you entities. Now all three entities have a field of type "AuditInfo".

You also could create an Interface in your code and make those entities to implement it. As I said before, all depends on why are you trying to do with this, but I think inheritance is not designed for this scenarios.

David Elizondo | LLBLGen Support Team
A.Alamo
User
Posts: 12
Joined: 12-Aug-2011
# Posted on: 16-Aug-2011 09:35:46   

I think that this could be a good scenario for inheritance because i am changing the behavior of the entity if its of this type, also allows me to write c# extensions for those entities only that will soft-delete and other stuff.

The only thing i am not shure is about creating a table that will hold one record for every record in other tables that inherits from this type.

I think i will use an interface as you said.

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 16-Aug-2011 09:44:12   

The only thing i am not shure is about creating a table that will hold one record for every record in other tables that inherits from this type.

IMHO there should be no pain with this, as the tables will be joined by PKs, which are already indexed, so joins should project no overhead. But anyway you may need to run your own tests, to validate this.