views:

89

answers:

1

Say I have two classes and have a requirement that the primary key property must be named "Id" (example: Book and Publisher). The requirement is because I'm working with our companies code generated objects and can't change the way they are generated. These classes have a a foreign key between them: Book to Publisher and is a one to one relationship, where in this case, each Book only has one Publisher.

In order to use Book.Publisher as a property in .Net RIA Services, you need to add the attributes. For example in the meta data for the Book class:
[Key] public int Id; ... [Include]
[Association("Book_Publisher", "Id", "Id", IsForeignKey = true)]
public Publisher Publisher;

In the meta data for the publisher class:
[Key]
public int Id;
...

In the client code I attempt to get the Publisher: Publisher booksPublisher = Book.Publisher; But I get the wrong publisher (or a null). After looking at the database, the Publisher id is it looking for is the id of the book, not the publisher.

Can I add an alias in the meta data? Will later versions of RIA Services handle this?

Thank you.

A: 

Just a guess...but I think the reason you're having issues is because you're trying to key the Id field from the Book object to the Id field of the Publisher object. I'm guessing that Book.Id uniquely identifies the book, not the publisher.

Does the Book object have a field called publisherId or something similar? If so, you should be keying the Book to Publisher using Book.publisherId = Publisher.Id.

Justin Niessner
I had to add the different keys to make it work.[Association("Book_Publisher", "BookId", "PublisherId", IsForeignKey = true)]public Publisher publisher;
Kevin