Print Page | Close Window

Defining new navigation properties in code

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2106
Printed Date: 08-Apr-2025 at 1:48am


Topic: Defining new navigation properties in code
Posted By: kpozin
Subject: Defining new navigation properties in code
Date 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?



Replies:
Posted By: GregD
Date 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. 




Print Page | Close Window