New Posts New Posts RSS Feed: Defining new navigation properties in code
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Defining new navigation properties in code

 Post Reply Post Reply
Author
kpozin View Drop Down
Newbie
Newbie


Joined: 30-Aug-2010
Posts: 4
Post Options Post Options   Quote kpozin Quote  Post ReplyReply Direct Link To This Post Topic: Defining new navigation properties in code
    Posted: 30-Aug-2010 at 7:37am
My database has some foreign key relationships that exist in the tables but are not formally specified by SQL Server foreign key constraints, and are therefore not visible to the Entity Framework. The schema is somewhat inflexible, so I'd like to extend a DevForce-generated entity partial class in the shared code to provide access to these "navigation properties" on both the server and the client side.

For example, I might have Contact, Company, and Address tables. I would want to make a property that will return a Contact's Company's Address object. I would want to extend the Contact class and add a CompanyAddress { get; } property (a setter would be great, too). Or Contact might have a PersonId field, but be missing a foreign key constraint to the Person table.

What's the best way to expose such queries in new shared properties? Which attributes should I include? Which methods should I be calling to ensure that asynchronous access and DevForce interceptor actions continue to work?
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 30-Aug-2010 at 2:39pm
You can write your own properties in the developer partial classes.

In the Silverlight _MiniDemos app for Business Object Persistence, see the following demo methods:
  • DisplayAllEmployeesWithTotalOrderRevenuesSyncProperty()
  • GetEmployeeWithTotalOrderRevenueAsyncProperty()
  • DisplayAllEmployeesWithTotalOrderRevenuesAsyncProperty()
  • GetEmployeeWithTotalOrderRevenueAsyncMethod()
and the corresponding properties and methods defined in the Employee partial developer class.  These illustrate several different approaches to writing a property that requires data retrieval in an async environment.

You might also be able to add associations in the conceptual model and have DevForce generate the navigation properties for you. I haven't used that approach, but it might be worth looking into. 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down