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();
  • 相关阅读:
    领域驱动设计精简版--阅读笔记
    ATM机的面向对象分析--笔记
    第一部分 Spring 基础
    spring in action 5 笔记--spring 实战 第4版和第5版对比
    Redis深度历险
    《Spring in action》之Spring之旅
    递归算法(java)
    java中static学习总结
    浅谈HookSSDT和和Resume(恢复)SSDT
    转---派遣例程与IRP结构
  • 原文地址:https://www.cnblogs.com/bruceleeliya/p/3147929.html
Copyright © 2011-2022 走看看