0

I have a table A that has a references to a table B through a third table C. C contains the primary key of A and B. For each A there is at most one record in C. When I try to create a mapping for A such that I am referencing B, I use the References function, but it does not allow me to specify that the mapping goes through another table and not directly. What is the proper way to do that?

eulerfx
  • 36,769
  • 7
  • 61
  • 83
  • Is there a special reason for the table C to exist? Because looking at the DB design it doesn't look like a one to one mapping. – gcores Mar 01 '09 at 23:59
  • one reason is that its legacy code, another is to prevent the main table (A) from having too many columns. – eulerfx Mar 02 '09 at 00:38

2 Answers2

0

The only mapping that I know that could do that would be a HasManyToMany in the mapping of A :

HasManyToMany(x => x.B)
    .WithTableName("C")
    .WithParentKeyColumn("A_Id")  
    .WithChildKeyColumn("B_Id"); 

The problem is that the mapping is for A having a list of Bs, not just one. I don't know how you could do it to get only one in a clean way.

gcores
  • 12,376
  • 2
  • 49
  • 45
0

I believe I have found the answer in google code samples. In the mapping class, it is possible to write an additional:

WithTable("SomeTable", c => { c.Map(x => x.Col1); });
eulerfx
  • 36,769
  • 7
  • 61
  • 83