2010-09-02 236 views
0

我正在尝试创建一个映射,以便从下面的查询中获取结果。 我很难得到设置的产品映射,以在3列上设置对Product_Line的引用,就像在哪里条件一样。我如何使用流利来实现这一点?流利的nhibernate映射

产品表:CID,PROJID,线路等,列 Product_Line表:CID,PROJID,线路等,列

,选择F *从乘积F 加入上f.cId Product_Line诉= v.CId和f.ProjID = v.ProjID and f.line = v.line

在此先感谢。 RajeshC

首先,非常感谢您寻找到它,并在这里与更多的信息: //所需物品:我想查询产品,例如,如果没有PRODUCTLINE,然后我想创建一个PRODUCTLINE,如果有一个,那么我会更新它。

public class ProductMap : ClassMap<Product> 
{ 
    Id(x => x.Id); 
    Map(x => x.CustomerId, "CustId"); 
    Map(x => x.ProjId, "PROJId"); 
    Map(x => x.LineNumber, "LineNumber"); 
    Map(x => x.ReportType, "ReportType"); 
// Reference to Product_Line? - this reference should be based on three columns (custId, ProjId, LineNumber) 
    References(x => x.Line); 
} 

public class ProductLineMap : ClassMap<ProductLine> 
{ 
    Table("Product_Line"); 
    Map(x => x.CustomerId, "CustId"); //same column as Product.CustId 
    Map(x => x.ProjId, "PROJId"); //Same as Product.ProjId 
    Map(x => x.LineNumber, "LINENUMBER"); //Same as Product.LineNumber 
    //etc., 
    //for me, this reference is not needed as I need from Product to ProductLine - one way. 
    //References(x => x.Product).Column("ProjId") // 
} 

回答

0

我们可以给你一个更好的答案,如果你向我们展示你的C#代码,并包裹在SQL中< code>标记......这是我的猜测是我认为你想:

public class ProductMap : ClassMap<Product> 
{ 
    Id(x => x.Id); 
    References(x => x.Line); // Reference to Product_Line? 
    // etc. 
} 

public class ProductLineMap : ClassMap<ProductLine> 
{ 
    Table("Product_Line"); 
    Id(x => x.Id).Column("cId"); 
    References(x => x.Product).Column("ProjId") 
} 
+0

我更新了代码示例。提前致谢。 – rajeshC 2010-09-02 15:45:24

+0

如何使用HasOne这样? (m => m.Line).ForeignKey(“CustId”)。ForeignKey(“PROJId”)。ForeignKey(“LINENUMBER”); – rajeshC 2010-09-02 16:09:09