Programming Entity Framework
Programming Entity Framework By Julia Lerman
February 2009
Pages: 828


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Using Defining Query To Create Your Own Views, Creating the Association on Page 376
Bob Bedell
post Nov 4 2009, 05:07 PM
Post #1


Active Member
**

Group: Members
Posts: 15
Joined: 3-November 09
Member No.: 20,856



Hi Julie,

If you get a chance, ran into another bump: Creating an association between the new UnpaidReservation entity and the Reservation entity. I know you're extremely busy, so please disregard my previous post. I'm more concerned about this one, because you are keeping the DefiningQuery as a permanent addition to the model going forward. I'd really like to get it to run. All the code I'm using is straight out of the walk-through.

Here's my problem:

1. UnpaidReservation has a Key of ReservationID.
2. Reservation has a Key of ReservationID.
3. The One to Many association - 'ReservationUnpaidReservation' - maps the Reservation entity's Key to the UnpaidReservation entity's Key.

How is this possible? Shouldn't the Reservation entity have to map its Key to a FORIEGN KEY defined in the many-side entity (virtual table). But there is no foreign key defined in the many-side entity.

What we end up with - as illustrated in the book - is the Store.UnpaidReservations.ReservationID property mapped to TWO other properties: both the BAModel.UnpaidReservation.ReservationID and the BAModel.Reservation.ReservationID.

The Entity Framework doesn't like this. When I run the code in Example 13-9, page 377, I get:

QUOTE
error 3021: Problem in Mapping Fragment starting at line 354:

Each of the following columns in table UnpaidReservations is mapped to multiple conceptual side properties:

UnpaidReservations.ReservationID is mapped to

ReservationUnpaidReservation.UnpaidReservation.ReservationID,
ReservationUnpaidReservation.Reservation.ReservationID


My AssociationSetMapping that is causing the problem:

CODE
<AssociationSetMapping Name="ReservationUnpaidReservation"
                                 TypeName="BAModel.ReservationUnpaidReservation"
                                 StoreEntitySet="UnpaidReservations">
            <EndProperty Name="UnpaidReservation">
              <ScalarProperty Name="ReservationID" ColumnName="ReservationID" />
            </EndProperty>
            <EndProperty Name="Reservation">
              <ScalarProperty Name="ReservationID" ColumnName="ReservationID" />
            </EndProperty>
          </AssociationSetMapping>


Thanks,

Bob



Go to the top of the page
 
+Quote Post
Bob Bedell
post Nov 4 2009, 06:20 PM
Post #2


Active Member
**

Group: Members
Posts: 15
Joined: 3-November 09
Member No.: 20,856



QUOTE
How is this possible? Shouldn't the Reservation entity have to map its Key to a FORIEGN KEY defined in the many-side entity (virtual table). But there is no foreign key defined in the many-side entity.


Found the foreign key!!! You include it in your Chapter 14 version of the model. It just isn't included in the Chapter 13 walk-through. So if one runs Example 13-9 against the Chapter 14 model, all is well.

Only glitch with the Chapter 14 model: The Activity entity doesn't have a Category scalar property (I don't know if you loose it in Chapter 14 yet or not). But to use the model for my chapter 13 purposes, I had to add the Category property to the Activity entity because the column Activities.Category in the SSDL table Activities must be mapped.

So all is well, 'cept since I figured this one out, if you get a chance, I'd still be interested in your thoughts about my Native Query post.

Glitches are good (and inevitable). Working them out forces one into the inner workings of this beast. Its taken me three weeks, but I'm getting it.

Thanks,

Bob

Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 22nd November 2009 - 05:10 AM