This is a migrated thread and some comments may be shown as answers.

zero or one to many relationships

2 Answers 110 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 1
Erik asked on 01 Aug 2012, 09:43 AM
I'm just getting started with OpenAccess ORM and I have a beginners question:

I have 2 entities Book and Page that have a 0..1 - * relationship, so a Book can contain many Pages, and a Page can be part of 1 Book, or not be in a Book. Page has a property BookId that serves as the foreign key to the primary key column of Book.

If I create an instance of Page, and don't provide it with a Book object, when saving changes to the database I get a constraint violated exception: page.book_id may not be NULL

How should I model this so that I can have a Page without a Book? (e.g. keep Page.Book as null)

2 Answers, 1 is accepted

Sort by
0
Accepted
DuelingCats
Top achievements
Rank 2
answered on 01 Aug 2012, 11:36 AM
In the entity designer, right click on your foreign key property and see if you have nullable set to true.
0
Erik
Top achievements
Rank 1
answered on 01 Aug 2012, 04:10 PM
Doh it was that simple, should have figured that one out.

Thanks for the tip :)
Tags
Getting Started
Asked by
Erik
Top achievements
Rank 1
Answers by
DuelingCats
Top achievements
Rank 2
Erik
Top achievements
Rank 1
Share this question
or