Is it possible to create associations with KeyMembers that aren't properties of the object?

Sep 17, 2009 at 11:16 PM
Edited Sep 17, 2009 at 11:32 PM

I've ran into scenarios where I want to set up an association, but my KeyMember doesn't belong to the parent CLR object.


  <Entity Id="SimpleObjects">
    <Table Name="vwSimpleObjects"/>
    <Column Member="SimpleObjectId" Name="Id" IsPrimaryKey="true"/>
    <Column Member="Name"/>

  <Entity Id="ComplicatedObjects">
    <Table Name="vwComplicatedObjects"/>    
    <Column Member="Name"/>
    <Association Member="SimpleObjects" KeyMembers="DONTHAVEONE" RelatedEntityID="SimpleObjects" RelatedKeyMembers = "SimpleObjectId"/>

A simple work around would just be to add another property to my "ComplicatedObject" CLR class, ComplicatedObjectId, and use that. But I was hoping to avoid the clutter. It makes sense in this example, but another object model would get littered with Id's that it didn't really need. Is there anyway to set up an association with a KeyMember that doesn't belong to the CLR object?

Any advice would be much appreciated! Thanks!

P.S. I have noticed that the Northwind samples always conveniently use the tables primary key as the KeyMember since it's the foreign key in another table. So the Northwind sample, at first glance at least, doesn't have something like this.

Sep 20, 2009 at 12:12 AM

No, there is not currently a way to do that.  Each entity has to define all its data fields.