0

私はNHibernateの料理3.0と流暢なチュートリアルを読んでいると私は(それ自体で料理はさまざまな方法があります)私はどちらを使うべきですか?流暢なチュートリアルや料理本3.0から? (

流暢NHibernateはチュートリアルに

private static ISessionFactory CreateSessionFactory() 
{ 
    return Fluently.Configure() 
    .Database(
     SQLiteConfiguration.Standard 
     .UsingFile("firstProject.db") 
    ) 
    .Mappings(m => 
     m.FluentMappings.AddFromAssemblyOf<Program>()) 
    .ExposeConfiguration(BuildSchema) 
    .BuildSessionFactory(); 
} 

private static void BuildSchema(Configuration config) 
{ 
    // delete the existing db on each run 
    if (File.Exists(DbFile)) 
    File.Delete(DbFile); 

    // this NHibernate tool takes a configuration (with mapping info in) 
    // and exports a database schema from it 
    new SchemaExport(config) 
    .Create(false, true); 
} 

料理3.0 PGを使用すべき1私はちょっと混乱しています76)ウェブリクエスト

1. In the hibernate-configuration section of web.config, add the current_ 
session_context_class property with a value of web. 

2. If it doesn't exist already, add a new Global application class (Global.asax). 

3. In Global.asax, add these using statements. 

using NHibernate; 
using NHibernate.Cfg; 
using NHibernate.Context; 

4. Create a static property named SessionFactory. 

public static ISessionFactory SessionFactory { get; 
private set; } 

5. In the Application_Start method, add the following code. 

protected void Application_Start(object sender, EventArgs e) 
{ 
    log4net.Config.XmlConfigurator.Configure(); 
    var nhConfig = new Configuration().Configure(); 
    SessionFactory = nhConfig.BuildSessionFactory(); 
} 
6. In the Application_BeginRequest method, add the following code. 
protected void Application_BeginRequest(object sender, EventArgs e) 
{ 
    var session = SessionFactory.OpenSession(); 
    CurrentSessionContext.Bind(session); 
} 

7. In the Application_EndRequest method, add the following code: 
protected void Application_EndRequest(object sender, EventArgs e) 
{ 
    var session = CurrentSessionContext.Unbind(SessionFactory); 
    session.Dispose(); 
} 

次に、これらを使用して実行します。私は一般的にasp.net MVCアプリケーションでそのコードを配置する場所、私もちょっと混乱しています流暢なチュートリアルを

Guid productId = new Guid(Request["id"]); 
Eg.Core.Product product; 
var session = Global.SessionFactory.GetCurrentSession(); 
using (var tran = session.BeginTransaction()) 
{ 
    product = session.Get<Eg.Core.Product>(productId); 
    tran.Commit(); 
} 
Page.Title = product.Name; 
Label1.Text = product.Name; 
Label2.Text = product.Description; 

。リポジトリパターンをninject(DI注入)で使用しようとしています。

私はどちらの方法でも、ninjectとリポジトリパターンをどのように動作させるかわかりません。

リポジトリパターンとDiのどちらの方が良いですか?

答えて

0

プロジェクトを実行するためのソリューション全体をダウンロードしようとしましたか?これらはコードのサンプルであり、エンティティクラス、マッピング、リポジトリを持つVSプロジェクトです。

http://www.sharparchitecture.net/https://github.com/sharparchitectureには、必要なセットアップがあるNorthwindサンプルプロジェクトをダウンロードします。 Northwindデータベースを見つけてローカルマシンにインストールし、データベースを指すようにNHibernate.configを変更する必要があります。

+0

私は本のソースコードをダウンロードしましたが、それらのソリューションファイルがないようです。 – chobo2

関連する問題