views:

20

answers:

1

I have the following tables:

A
--
Id : int
SomeString : varchar(20)

B
--
Id : int
BString: nvarchar(10)
AId : int // FK to A

I have an entity A which is already mapped to the table A.

For the entity B, I'm trying to do a composite so that I have all the data from B, as well as the fields from A. The fields from A shouldn't be changable via B though, they're just there for the use case.

I'm trying to build my (fluent) mapping for B like so:

  Table("B");
  Join(
    "A"
    m =>
      {
        m.KeyColumn("AId");
        m.Inverse();
        m.Map(p => p.SomeString);
      }
  );
  Map(p => p.BString);

The problem occurs when I try to export the schema; it says the table A already exists. Any ideas, or doesn't this work at all?

Thanks

+1  A: 

This is a bad idea. You should just reference A.

If you don't want to change A from B's reference, just make it private and expose only getters for its properties.

Diego Mijelshon
That's what I ended up doing. I don't see why it would be a bad idea (except that it seems NHibernate doesn't seem to let you do it). Joining a table and setting those properites readonly in the mapping for the join doesn't pose an conceptual problem, and it eliminates needing to load another fairly complex model just to get a couple of properties. In our case, this other model can't be private because we're using Fluent to do our mappings.
Andy