DataVeryLite入门教程(一) 配置篇
DataVeryLite 是基于.net 4.0的数据库持久化ORM框架.
1.连接字符串配置
a,App.config/Web.config配置方式
<add name="myConnetion" connectionString="Data Source=host;Initial Catalog=db;Integrated Security=True" providerName="sqlserver"/>
需要说明的是 name connectionString和providerName三个属性缺一不可
| DataBase | Connection String sample | providerName |
|---|---|---|
| Sqlite | Data Source=path;Version=3; | sqlite |
| Access | Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path | access |
| MySql | server = host; user id = name; password = pwd; database = db; | mysql |
| PostgreSql | Server= host;User Id=name;Password=pwd;Database=db; | postgresql |
| SqlServer | Data Source=host;Initial Catalog=db;Integrated Security=True | sqlserver |
| Db2 | Database=db;User ID=name;Server=host;password=pwd | db2 |
| Oracle | Data Source=XE;User Id=name;Password=pwd; | oracle |
public class MyConnectionStringProvider : ConnectionStringSettingsProvider
{
public override List<ConnectionStringSettings> ToConnectionString()
{
var sqlServverConnStr = new ConnectionStringSettings
{
Name = "sqlserver1",
ConnectionString = "Data Source=host;Initial Catalog=db;Integrated Security=True",
ProviderName = "sqlserver"
};
var mysqlConnStr = new ConnectionStringSettings
{
Name = "mysql1",
ConnectionString = "server = host; user id = name; password = pwd; database = db;",
ProviderName = "sqlserver"
};
return new List<ConnectionStringSettings>() { sqlServverConnStr,mysqlConnStr };
}
}
2,数据库映射
[DataBase(Key = "sqlserver1")]
public class Dandelion : DataVeryLite.Core.EntityPool
{ }
DataBaseAttribute中的Key属性对应的连接字符串配置中的key值,这样Dandelion会自动加载数据库上下文信息。
[Table(Name = "Person" , EntityPool = typeof(Dandelion))]
public partial class Person : DataVeryLite.Core.Entity
{
[Column(Name = "Id", IsPrimaryKey = true)]
public int Id { get; set; } [Column(Name = "Name")]
public string Name{ get; set; } [Column(Name = "Sex")]
public string Sex { get; set; } [Column(Name = "Phone")]
public string Phone { get; set; } [Column(Name = "Email")]
public string Email { get; set; }
}
TableAttribute中的Name为表的名字。可以不设置,这时Person的类名就对应表的名字,如果我们需要类名和表名不一致,这时可以设置Name。
Configure.SetKey = (sender) => "sqlserver1";
或
Configure.SetKey = (sender) =>
{
if (sender is Dandelion)
{
return "sqlserver1";
}
else
{
return "mysql1";
}
};
项目地址 http://dataverylite.codeplex.com/
NuGet
PM> Install-Package DataVeryLite
Example lite
using System;
public class HelloWorld
{
public static void Main(params string[] args)
{
var p=Models.Xe.Person();
p.Load(By.Id(1));
p.Del();
Console.WriteLine(p.Name+","+p.Age);
}
}
DataVeryLite入门教程(一) 配置篇的更多相关文章
- DataVeryLite入门教程(二) Entity篇
DataVeryLite 是基于.net 4.0的数据库持久化ORM框架. 目前支持的数据库有Sqlserver,Mysql,Oracle,Db2,PostgreSql,Sqlite和Access. ...
- Systemd 入门教程:实战篇
Systemd 入门教程:实战篇 上一篇文章,介绍了 Systemd 的主要命令,这篇文章主要介绍如何使用 Systemd 来管理我们的服务,以及各项的含义: 一.开机启动 对于那些支持 System ...
- Spring Cloud 入门教程 - 搭建配置中心服务
简介 Spring Cloud 提供了一个部署微服务的平台,包括了微服务中常见的组件:配置中心服务, API网关,断路器,服务注册与发现,分布式追溯,OAuth2,消费者驱动合约等.我们不必先知道每个 ...
- 【转帖】Systemd 入门教程:命令篇
Systemd 入门教程:命令篇 Copy From http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html 感觉 ...
- Linux Capabilities 入门教程:概念篇
原文链接:Linux Capabilities 入门教程:概念篇 Linux 是一种安全的操作系统,它把所有的系统权限都赋予了一个单一的 root 用户,只给普通用户保留有限的权限.root 用户拥有 ...
- Linux 命令详解(八)Systemd 入门教程:实战篇
Systemd 入门教程:实战篇 http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html
- Linux 命令详解(七)Systemd 入门教程:命令篇
Systemd 入门教程:命令篇http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
- (转)Systemd 入门教程:命令篇
Systemd 入门教程:命令篇 原文:http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html Systemd 入门 ...
- SSH(Struts2+Spring4+Hibernate4)框架教程之配置篇
SSH(Struts2+Spring4+Hibernate4)框架教程之配置篇 - 若明天不见 - 博客频道 - CSDN.NEThttp://blog.csdn.net/why_still_conf ...
随机推荐
- Vue挂载元素的替换
Vue根组件已有挂载DOM'#app',在render又引进一个组件,该组件最外层也是用了'#app',为何根组件的DOM'#app'会被替换掉. //main.js import Vue from ...
- 【心情】CF
感觉CF上最后做出来的人数1500左右的题就是我的智商极限了. 去找那样的题练练吧.
- JavaScript window.location物
演示样例 注意 方法 常常使用window.location.它的结构总是记不住.简单梳理下.方便以后查询. 演示样例 URL:http://b.a.com:88/index.php? name=ka ...
- svg查看预览 , 鼠标控制放大缩小 , 托拉拽等
自己写是不可能了 , 所以要借用插件 svg-panzoom.js 地址 : https://github.com/ariutta/svg-pan-zoom#demos 及常见问题https://ww ...
- Object-c学习笔记(1)
说明:本人用的win8 系统装Code::Blocks练习OC. 1.类的声明和实现的关系图: @interface就好像暴露在外面的时钟表面 @implementation就好像隐藏在时钟内部的 ...
- Method for browsing internet of things and apparatus using the same
A method for browsing Internet of things (IoT) and an apparatus using the same are provided. In the ...
- FastDFS安装、配置、部署(三)-Storage配置具体解释
1.基本配置 # is this config file disabled # false for enabled # true for disabled disabled=false # the n ...
- python中的验证码识别库PyTesser
PyTesser PyTesser is an Optical Character Recognition module for Python. It takes as input an image ...
- VC除零异常(错误)捕获
// testFinally.cpp : Defines the entry point for the console application. // #include "stdafx.h ...
- android反射组件 (一个)java 它们的定义annotation基础知识
它们的定义annotation它由三部分组成: 它们的定义annotation.使用annotation班.annotation的处理方法. 一.自己定义annotation 元注解包含下面: 1) ...