c# - EF Architecture, adding inherited entity to an existing table -


i´m not sure achieved, therefore ask guys!

say have existing table contains book register books written. can call table "books" (entity), , has bookid, booktitle , bookdescription. i´m using ef , database first approach, , working dbcontext.

very simple structure, know sell books , want take advantage of existing books table register users can browse on homepage. have used books sale want connect books table somehow.

in world structure base class named "book", , derived classes "newbook" , "usedbook", i`m totally lost how can achieve existing books table , entity framework.

i've had implement inheritance in ef in project , found difficult when creating subclasses tables in database first. instead, added subclasses entities in ef model, generated database script, , ran script add tables database. here steps took:

  1. in ef model diagram .edmx file right click background , add new... entity.
  2. type in entity name (in example usedbook) , select base type book.
  3. after clicking ok can add properties usedbook.
  4. right click background again , select generate database model. generate sql file.
  5. now if have data in existing database not want execute entire script drop existing tables. instead, find references of new table usedbook (will called books_usedbook in database) , execute lines. may need manually change reference book table may have pluralized incorrectly. make sure book table name in script matches what's in database.
  6. after executing script, go .edmx model, right click background, , select validate. shouldn't have errors here.
  7. in database have class books_usedbook bookid column referencing bookid column in books table.

hope helps!


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -