Fluent Hibernate Mapping hitch - 为子类传递错误的列名

时间:2011-06-22 10:26:22

标签: nhibernate fluent-nhibernate

我完成了nhibernate屏幕演员的夏天,我试图将它转换为流利,只是为了知识。

我有两个班级(非常简单)

public class Customer { ... }
public class PreferredCustomer : Customer { ... }

这些遵循table per sub class策略,因此流畅的映射是这样的:

CustomerMap - 
  //nothing related to PreferredCustomer - the spec says not required
public class PreferredCustomerMap : SubclassMap<PreferredCustomer>
{
    Map(x => x.CustomerSince);
    Map(x => x.OrderDiscountRate);
}

多数民众赞成。 我的测试失败了,经过检查,它抱怨sql找不到列customer_id

这是hibernate生成的sql:

SELECT  customer0_.CustomerId as CustomerId1_0_, 
   customer0_.Version as Version1_0_, 
   customer0_.Firstname as Firstname1_0_, 
   customer0_.Lastname as Lastname1_0_, 
   customer0_1_.CustomerSince as Customer2_2_0_, 
   customer0_1_.OrderDiscountRate as OrderDis3_2_0_, 
       //here, customer0_1_.customer_id needs to be CustomerID really.
   case when customer0_1_.Customer_id is not null then 1 when customer0_.CustomerId is not null then 0 end as clazz_0_ 
    FROM [Customer] customer0_ left outer join [PreferredCustomer] customer0_1_ on customer0_.CustomerId=customer0_1_.Customerid 
    WHERE customer0_.Customer_Id=1

它显然只在PreferredCustomer加入表上。无法找到需要做的事情。

有什么想法吗?

编辑:如何读取由流畅生成的xml?这可能是一个好的开始。

1 个答案:

答案 0 :(得分:2)

您需要在SubclassMaps中调用KeyColumn("CustomerID");