English 中文(简体)
通過額外的表格進行 Fluent NHibernate 一對一映射
原标题:
  • 时间:2009-03-01 23:47:37
  •  标签:

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?

最佳回答

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); });
问题回答

我所知道唯一能做到这一点的映射是在A的映射中使用HasManyToMany。

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

问题在于映射是A拥有B列表,而不仅仅是一个。我不知道你如何以清晰的方式仅获取一个。





相关问题
热门标签