2010-09-02 230 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