zoukankan      html  css  js  c++  java
  • Castle.ActiveRecord (V3.0.0.130)

    为项目添加 Castle.ActiveRecord 的引用:

    安装成功后,查看项目的引用如图:

    配置文件 App.Config (MySQL)

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
      </configSections>
      <activerecord>
        <config>
          <add key="connection.driver_class" value="NHibernate.Driver.MySqlDataDriver" />
          <add key="dialect" value="NHibernate.Dialect.MySQL5Dialect" />
          <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
          <add key="connection.connection_string" value="Server=localhost;Port=3306;Database=testDb;Uid=root;Pwd=mysql;Charset=utf8;" />
          <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
        </config>
      </activerecord>
    </configuration>

    初始化 (添加 System.Configuration.dll 的引用)

    Castle.ActiveRecord.Framework.IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
    Castle.ActiveRecord.ActiveRecordStarter.Initialize(source, new Type[] { typeof(User) });

    实体类

        [ActiveRecord("user")]
        class User: ActiveRecordBase<User> //ActiveRecordValidationBase<User>
        {
            [PrimaryKey(PrimaryKeyType.Identity, Column = "ID")]
            public int ID { get; set; }
            [Property(Column = "Name")]
            public string Name { get; set; }
        }

    UI 上的使用:

    dataGridView1.DataSource = User.FindAll();
  • 相关阅读:
    体验cygwin纪实
    播布客视频PIT专用播放器MBOO2015
    rpm基本命令参考
    rhel7.x配置本地yum
    mtr网络连通性测试
    Oracle下载汇聚
    Spring Cloud心跳监测
    Hystrix的用法
    Redis系列十:缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级
    dubbo异步调用三种方式
  • 原文地址:https://www.cnblogs.com/bruceleeliya/p/3147929.html
Copyright © 2011-2022 走看看