Chr*_*ian 5 nhibernate fluent-interface fluent
我刚刚爱上了NHibernate和流畅的界面.后者支持非常好的映射和重构支持(不再需要xml文件).
但没有人是完美的,所以我错过了流利的多对多映射.有人知道它是否已经存在吗?如果是这样,一行简单的代码就会很好.
但要坚持问题的标题,有没有办法结合流畅和正常的NHibernate映射.
目前我使用以下行进行我的测试设置WITH Fluent,以及第二个代码块用于我的测试WITHOUT流畅(使用XML映射).如何判断流利使用流畅的IF AVAILABLE和XML否则......
var cfg = new Configuration();
cfg.AddProperties(MsSqlConfiguration.MsSql2005.ConnectionString.Is(_testConnectionstring).ToProperties());
cfg.AddMappingsFromAssembly(typeof(CatMap).Assembly);
new SchemaExport(cfg).Create(true, true);
var persistenceModel = new PersistenceModel();
persistenceModel.addMappingsFromAssembly(typeof(CatMap).Assembly);
IDictionary<string, string> properties = MsSqlConfiguration.MsSql2005.UseOuterJoin().ShowSql().ConnectionString.Is(_testConnectionstring).ToProperties();
properties.Add("command_timeout", "340");
session = new SessionSource(properties, persistenceModel).CreateSession();
Run Code Online (Sandbox Code Playgroud)
没有流利......
config = new Configuration();
IDictionary props = new Hashtable();
props["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
props["dialect"] = "NHibernate.Dialect.MsSql2005Dialect";
props["connection.driver_class"] = "NHibernate.Driver.SqlClientDriver";
props["connection.connection_string"] = "Server=localhost;initial catalog=Debug;Integrated Security=SSPI";
props["show_sql"] = "true";
foreach (DictionaryEntry de in props)
{
config.SetProperty(de.Key.ToString(), de.Value.ToString());
}
config.AddAssembly(typeof(CatMap).Assembly);
SchemaExport se = new SchemaExport(config);
se.Create(true, true);
factory = config.BuildSessionFactory();
session = factory.OpenSession();
Run Code Online (Sandbox Code Playgroud)
就是这样......克里斯
PS:我真的很喜欢这个网站,GUI很完美,所有文章的质量都令人难以置信.我认为这将是巨大的:-)必须注册...
映射从Foo到Baa:
HasManyToMany< Baa > ( x => Baas )
.AsBag ( ) //can also be .AsSet()
.WithTableName ( "foobar" )
.WithParentKeyColumn ( "fooId" )
.WithChildKeyColumn ( "barId" ) ;
Run Code Online (Sandbox Code Playgroud)
查看中的示例ClassMapXmlCreationTester- 它们还显示了默认列名称是什么。
| 归档时间: |
|
| 查看次数: |
3658 次 |
| 最近记录: |