2009-05-04 7 views
0

私は流暢なnhibernateを使用しています。流暢なnhibernateに参加する

例:

iは3つのテーブルを持っている、すなわち

CUSTOMER 得意先PK のCustomerName

PRODUCT 商品コードPK 商品名

Cust_Product cust_prodId PK のProductId FK 得意先FK

は今、私は顧客名を表示したいので、

をproductnae、どのように私は同じのためのマッピングクラスを記述します。

私は

session.CreateCriteria(typeof演算( "クラス名を"))を使用します。リスト()このような 。どのように私はこれを行うのですか..?

答えて

0

詳細については、FNH wikiまたはGoogleからの多数のブログ投稿の1つをお勧めします。

ここでは多対多の関係を実装しようとしていますが、それは多くの人を捨ててしまうようです。ここでは目安だ:あなたのProductクラスに、

IList<Product> Products { get; private set; } 

と同様:

あなたのCustomerクラスでは、次のようなコレクションをする必要があります

IList<Customers> Customers { get; private set; } 

あなたは多対を始めますHasManyToMany関数を使用する多対多マップ:

public class CustomerMap : ClassMap<Customer> 
{ 
    public CustomerMap() 
    { 
     // other mappings 

     HasManyToMany<Product>(x => x.Products) 
      .WithTableName("Cust_Product") // Specifies the join table name 
      .WithParentKeyColumn("CustomerId") // Specifies the key joining back to this table (defaults to [class]_id, Customer_id in this case) 
      .WithChildKeyColumn("ProductId") 
      .FetchType.Join(); // Instructs NHibernate to use a join instead of sequential select 
    } 
} 

次に、もう一方のプロセスを繰り返します(ProductクラスのCustomersプロパティ)。

+0

スチュアートに感謝します... –