Castle ActiveRecord 使用动态填写参数方式配置数据库连接


有时候如果我们的配置信息是动态的获取,这种方式就会变得非常有用。

示例 C# 代码

usingSystem;
usingNUnit.Framework;

usingtest;

usingSystem.Reflection;

usingCastle.ActiveRecord.Framework.Config;
usingCastle.ActiveRecord;

namespacetest._TestUnitCase
{
/**////<summary>
///BlogTest的摘要说明。
///</summary>
[TestFixture]
publicclassBlogTest
{
publicBlogTest()
{
}

[Test]
publicvoidCreateBlogTest()
{
Assemblyassembly
=typeof(test.Blog).Assembly;

InPlaceConfigurationSourcesrc
=newInPlaceConfigurationSource();

Hashtableproperties
=newHashtable();
properties.Add(
"hibernate.connection.driver_class","NHibernate.Driver.SqlClientDriver");
properties.Add(
"hibernate.dialect","NHibernate.Dialect.MsSql2000Dialect");
properties.Add(
"hibernate.connection.provider","NHibernate.Connection.DriverConnectionProvider");
properties.Add(
"hibernate.connection.connection_string","UID=sa;Password=19811218;InitialCatalog=ARDemo;DataSource=.");
src.Add(
typeof(ActiveRecordBase),properties);

ActiveRecordStarter.Initialize(src,
typeof(Blog));


Blogblog
=newBlog();

blog.Name
="abcde1234";
blog.Author
="stephenabcdef";

Console.WriteLine(BlogManager.getInstance().CreateBlog(blog));
}
}
}
优质内容筛选与推荐>>
1、商业网站常用中英文对照表
2、35家上市公司公布2013年年报
3、PHP MySQL Update
4、shell脚本使用## or %%
5、文件操作_1-21 选择题


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号