1、ActiveRecord配置文件ARConfig.xml,并将配置文件的“生成操作”改成“嵌入的资源”

<?xml version="1.0" encoding="utf-8" ?>
<activerecord isWeb="true">
  <config>
    <add key="connection.driver_class" value="NHibernate.Driver.SQLite20Driver" />
    <add key="dialect" value="NHibernate.Dialect.SQLiteDialect" />
    <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="connection.connection_string" value="data source=|DataDirectory|\message.db;Version=3;" />
    <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"/>
    <add key="show_sql" value="true"/>
  </config>
</activerecord>

2、使用到的DLL文件

3、测试实体类UserInfo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using NHibernate;

namespace CY.Domain
{
    [ActiveRecord("T_User")]
    public class UserInfo : ActiveRecordBase
    {
        #region 属性

[PrimaryKey(PrimaryKeyType.Identity, "ID")]
        public int ID { get; set; }

[Property("UserName")]
        public string Name { get; set; }

[Property("Password")]
        public string Password { get; set; }

[Property("RegTime")]
        public DateTime RegTime { get; set; }

#endregion

#region 方法

public static void Insert(UserInfo user)
        {
            Save(user);
        }

public static IList<UserInfo> Select()
        {
            return (IList<UserInfo>)FindAll(typeof(UserInfo));
        }

public static UserInfo Query(int id)
        {
            object model = FindByPrimaryKey(typeof(UserInfo), id);

return model != null ? model as UserInfo : null;
        }

public static void Del(int id)
        {
            UserInfo model = Query(id);
            if (model != null)
            {
                Delete(model);
            }
        }
       
        #endregion
    }
}

4、初始化实体类对象(Global.asax)

using Castle.ActiveRecord;

using Castle.ActiveRecord.Framework.Config;

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();             RegisterRoutes(RouteTable.Routes);             XmlConfigurationSource source = new XmlConfigurationSource(Server.MapPath("ARConfig.xml"));
            ActiveRecordStarter.Initialize(source, typeof(UserInfo));
        }

5、使用

            for (int i = 0; i < 10; i++)
            {
                UserInfo.Insert(new UserInfo()
                {
                    Name = "user" + i.ToString(),
                    Password = "123456",
                    RegTime = DateTime.Now
                });
            }             IList<UserInfo> models = UserInfo.Select();
            ViewData["users"] = models;

记录Castle ActiveRecord访问Sqlite的配置的更多相关文章

  1. Castle.ActiveRecord多数据库配置

    最近使用Castle.ActiveRecord框架,网上关于多数据支持的文章很少,因此有了这篇博文的产生. 开发工具VS2015,Sql Server2008R2 新建数据库,数据初始化脚本如下: - ...

  2. Castle ActiveRecord配置中需要注意的地方

    关于Castle 的开发可参考李会军老师的Castle 开发系列文章,里面有关于ActiveRecord学习实践系列和Castle IOC容器系列两个部分,是比较好的教程. 这里主要说明在Castle ...

  3. Servlet、Tomcat访问(access)日志配置、记录Post请求参数

    一.运行环境: Maven:3.5.2(点击下载) ,下载页 Tomcat:8.5.29(点击下载) ,下载页 JDK:jdk1.7.0_80(点击下载) ,下载页 MavenDependency: ...

  4. Castle ActiveRecord学习(二)配置、引用、程序启动

    来源:http://www.cnblogs.com/zxj159/p/4082987.html 配置数据库驱动: Model层引用:Castle.ActiveRecord.dll.NHibernate ...

  5. Castle ActiveRecord框架学习(一)

    一.Active Record(活动记录)模式 Active Record是业务逻辑层中(<企业应用架构模式>将该模式归为数据源模式)常用的一种框架模式,尤其在底层数据库模型匹配业务模型时 ...

  6. Castle ActiveRecord学习实践

    Castle是针对.NET平台的一个开源项目,从数据访问框架ORM到IOC容器,再到WEB层的MVC框架.AOP,基本包括了整个开发过程中的所有东西,为我们快速的构建企业级的应用程序提供了很好的服务. ...

  7. Castle ActiveRecord学习(一)简介

    简介 来源:http://www.cnblogs.com/zxj159/p/4082987.html 一.Active Record(活动记录)模式 Active Record是业务逻辑层中(< ...

  8. Qt5 开发 iOS 应用之访问 SQLite 数据库

    开发环境: macOS 10.12.1 Xcode 8.1 Qt 5.8 iPhone 6S+iOS 10.1.1   源代码: 我在 Qt 程序里指定了数据库的名称来创建数据库,在 Win10.An ...

  9. windows10 下访问 virtualbox 虚拟机的linux15.10/16.04 系统 及 用 putty 访问虚拟机的配置

    参考: http://www.doc88.com/p-915707596190.html --- 安装samba http://my.oschina.net/u/2260265/blog/405598 ...

随机推荐

  1. HDFS的运行原理

    简介 HDFS(Hadoop Distributed File System )Hadoop分布式文件系统.是根据google发表的论文翻版的.论文为GFS(Google File System)Go ...

  2. 最新AFNetworking

    1.网络监测 /** * 网络检测 */ - (void)networkingMonitoring { //打开网络监测 [[AFNetworkReachabilityManager sharedMa ...

  3. POJ 3009 DFS+剪枝

    POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Acce ...

  4. OSX下Python模块安装常见问题解决

    he following error occurred while trying to add or remove files in theinstallation directory: [Errno ...

  5. 【转载】Python的包管理工具Pip

    接触了Ruby,发现它有个包管理工具RubyGem很好用,并且有很完备的文档系统http://rdoc.info 发现Python下也有同样的工具,包括easy_install和Pip.不过,我没有细 ...

  6. 论文笔记--Fast RCNN

    很久之前试着写一篇深度学习的基础知识,无奈下笔之后发现这个话题确实太大,今天发一篇最近看的论文Fast RCNN.这篇文章是微软研究院的Ross Girshick大神的一篇作品,主要是对RCNN的一些 ...

  7. fopen中r+和w+的区别

    r+: Open for reading and writing.  The stream is positioned  at  the beginning of the file. w+:Open ...

  8. 状态模式(State Pattern)

    当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类. 状态模式主要解决的是当控制一个对象状态的条件表达式过于复杂时的情况.把状态的判断逻辑转移到表示不同状态的一系列类中,可以把复杂 ...

  9. tiny java web server

    import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; ...

  10. Java高级开发工程师面试考纲 转

    转 http://www.sanesee.com/article/java-engineer-interview-of-content-tree 1 Java基础 1.1 Collection和Map ...