0

I'm currently writing a handy ticketsystem where tickets can be moved to an archive. The ticket entity has many properties and associations to other entities and if I'm right I could just draw an inheritance that inherits all those props and assoc. to an archive entity (see image).

entity framework inheritance

If my thought is correct I have no idea how to move an entry to the archive in code because I have no clue how to access this inherited archive... pseudocode that's not working

CodingYourLife
  • 7,172
  • 5
  • 55
  • 69

1 Answers1

1

Derived entities are part of the collections of their base entities.

To access the first derived entity, you can write

db.TicketSet.OfType<Archive>().First()

To add a derived entity, simply add it to the base collection.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • ok, that explains my var thatsNotPossible but still don't know how to fix my db.ArchiveSet.Add(db.TicketSet.First(x => x.Id == 123)); – CodingYourLife Feb 11 '13 at 22:52
  • 1
    @yourmother: AFAIK, Entity Framework does not have any way to convert a row from a base type to a derived type. You could delete it, then add a new instance of the derived entity with the same values. – SLaks Feb 12 '13 at 03:41