3

I have the following 2 tables TableA and ArchivedTableA. Basically They are identical tables, but rows from TableA are moved to ArchivedTable to archive them.

How can I represent this in entity Framework so that these 2 classes inherit from the same entity. I am using POCOs.

2 Answers 2

1

I would recommend not using inheritance in this situation. If you were to "archive" a record from TableA to ArchiveTableA it would still be in your base table.

Julie Lerman has a good MSDN article of some of the pitfalls of inheritance. http://msdn.microsoft.com/en-us/magazine/jj553510.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

I would create a base class with common properties for e.g.

     public class BaseEntity
    {
         public virtual int Id {get;set;}
         public DateTime CreatedOn  {get;set;}
    }

Then create POCO objects which inherit from this base class becouse they have common columns as follows ....

public class TableA : BaseEntity
{
   public string NewName {get;set;}
}

public class ArchivedTableA : BaseEntity
{
   public string Name {get;set;}
}

You obviously needs to do the DbSet Mapping etc in form of EF plumbing on top of this...

3 Comments

Do you mean to remove the T4 generation?
Not necessarily. T4 templates are just "Moulds" to generate your EF classes. You can create your own custom T4 templates which uses the inheritance modal as above. For start I would write all the classes by hand once you are happy with your object model then create your T4 templates from that object model.
thanks again for your reply. so it seems that out of the box, there is no one to achive this? - you would need to create your own T4 generation - right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.