Many To One without having both the entity and Id present?

Apr 9, 2009 at 3:28 PM
Edited Apr 9, 2009 at 3:33 PM
Does anyone know how to map a Many To one with out having the id member present?

Person
{
Id,  Name, Type
}

PersonType
{
Id, TypeName
}


Person has a column Type_ID

I want to define an association on Person to PersonType without having to have both the member Type and TypeId?

Thanks
Coordinator
May 7, 2009 at 12:50 AM
There is no support for this at present.  You would have to invent a new QueryMapping to do this.
Aug 1, 2012 at 1:23 PM
Edited Aug 1, 2012 at 1:41 PM

Probably the asker does not need any help any more but still I would like to answer for future reference.

Here is a work-around for duplicate association for foreign entity/table.

Person {
	Id,
	Name,
	// Use this valid way to set/associate Type
	Type,
	// Use read-only property
	public int TypeId
	{
		get { return Type == null ? 0 : Type.Id; }
	}
}

PersonType {
	Id,
	TypeName
}

<!-- Entity Map -->
<?xml version="1.0" encoding="utf-8"?>
<map>
  <Entity Id="PersonType">
    <Table Name="PersonTypes" />
    <Column Member="Id" IsPrimaryKey="true" IsGenerated="true" />
    <Column Member="TypeName" />
  </Entity>
  <Entity Id="Person">
    <Table Name="Persons" />
    <Column Member="Id" IsPrimaryKey="true" IsGenerated="true" />
    <Column Member="TypeId" />
    <Association Member="Type" KeyMembers="TypeId" RelatedEntityID="PersonType" RelatedKeyMembers="Id" />
  </Entity>
</map>

Also the Person entity needs to take care that its Type gets saved and Person.Type gets syncronised (Person.Type = syncronisedType).

So the Person entity still needs both the Type and TypeId properties but only Type can be set.