AutoPoco的使用
官方开发指导https://autopoco.codeplex.com/documentation
初步使用:
SimpleUser是自己要批量创建的类
1)创建管理工厂
IGenerationSessionFactory factory = AutoPocoContainer.Configure(x =>
{
x.Conventions(c =>
{
c.UseDefaultConventions();
});
x.AddFromAssemblyContainingType<SimpleUser>();
});
2) 从工厂中创建会话
IGenerationSession session = factory.CreateSession();
3) 使用会话创建集合,List中的100表示创建含一百个元素的集合,创建的时候并没对集合中的元素进行赋值。
SimpleUser user = session.Single<SimpleUser>().Get(); List<SimpleUser> users = session.List<SimpleUser>().Get();
在初步的基础上进行赋值
session.List<SimpleUser>()
.First()
.Impose(x => x.FirstName, "Rob")
.Impose(x => x.LastName, "Ashton")
.Next()
.Impose(x => x.FirstName, "Luke")
.Impose(x => x.LastName, "Smith")
.All().Random()
.Impose(x => x.Role,roleOne)
.Next()
.Impose(x => x.Role,roleTwo)
.Next()
.Impose(x => x.Role, roleThree)
.All()
.Invoke(x => x.SetPassword("Password1"))
.Get();
测试发现:
1、Next方法必须在First 或者Random使用之后才能使用,并且First只能使用一次在没调用All方法之前,First、Random、Next使用完之后必须调用All方法;
2、每次只能为一个属性赋值;
从数据源中创建
mFactory = AutoPocoContainer.Configure(x =>
{
x.Conventions(c =>
{
c.UseDefaultConventions();
});
x.AddFromAssemblyContainingType<SimpleUser>();
x.Include<SimpleUser>()
.Setup(c => c.EmailAddress).Use<EmailAddressSource>()
.Setup(c => c.FirstName).Use<FirstNameSource>()
.Setup(c => c.LastName).Use<LastNameSource>()
.Invoke(c => c.SetPassword(Use.Source<String, PasswordSource>()));
x.Include<SomeType>()
.Setup(c => c.SomeString).Use<RandomStringSource>(,);
});
Use中的泛型就是传递给集合元素实例数据源,是个类。该类必须继承抽象泛型类DatasourceBase<T> 泛型T表示对应属性的数据类型。该抽象类中只有一个抽象方法Next,该方法就是返回数据给属性,实现给属性赋值。从而达到数据绑定;
在Conventions中实现数据源绑定
For example
A convention to set all String EmailAddress properties to use the EmailAddressSource
public class EmailAddressPropertyConvention : ITypePropertyConvention
{
public void Apply(ITypePropertyConventionContext context)
{
context.SetSource<EmailAddressSource>();
}
public void SpecifyRequirements(ITypeMemberConventionRequirements requirements)
{
requirements.Name(x => String.Compare(x, "EmailAddress", true) == );
requirements.Type(x => x == typeof(String));
}
}
A convention to set all String EmailAddress fields to use the EmailAddressSource
public class EmailAddressFieldConvention : ITypeFieldConvention
{
public void Apply(ITypeFieldConventionContext context)
{
context.SetSource<EmailAddressSource>();
}
public void SpecifyRequirements(ITypeMemberConventionRequirements requirements)
{
requirements.Name(x => String.Compare(x, "EmailAddress", true) == );
requirements.Type(x => x == typeof(String));
}
}
x.Conventions(c => c.Register(typeof(IdPropertyConvention)));
x.AddFromAssemblyContainingType<SimpleUser>();
在context中有个Setvalue方法 ,应该是给绑定数据源传值的,测试使用的时候并没有效果,传递多个值理论是使用的数组。问题未解决。
AutoPoco的使用的更多相关文章
- .Net程序员飞扬有用的85个工具
1.Visual Studio Visual Studio Productivity Power tool:Visual Studio专业版(及以上)的扩展,具有丰富的功能,如快速查找,导航解决方案, ...
- 实用的VS工具
工具 1.Visual Studio Visual Studio Productivity Power tool:Visual Studio专业版(及以上)的扩展,具有丰富的功能,如快速查找,导航解决 ...
- 对ASP.NET程序员非常有用的85个工具
介绍 这篇文章列出了针对 ASP.NET 开发人员的有用工具. 工具 1. Visual Studio Visual Studio Productivity Power tool:Visual Stu ...
- 推荐几个对Asp.Net开发者比较实用的工具
推荐几个对Asp.Net开发者比较实用的工具.大家有相关工具也可以在评论区留言,一起努力学习. 工具 1.Visual stdio Productivity Power tool:visual std ...
- .Net开发工程师工具箱
Visual Studio Visual Studio Productivity Power tool:Visual Studio专业版(及以上)的扩展,具有丰富的功能,如快速查找,导航解决方案,可搜 ...
- asp.net 工具
http://www.jb51.net/article/92465.htm 这篇文章列出了针对ASP.NET开发人员的有用工具. 工具 1.Visual Studio Visual Studio Pr ...
随机推荐
- POI Excel导出样式设置
HSSFSheet sheet = workbook.createSheet("sheetName"); //创建sheet sheet.setVerticallyCente ...
- Codeforces Gym 100114 H. Milestones 离线树状数组
H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...
- .NET中的三种Timer的区别和用法
最近正好做一个WEB中定期执行的程序,而.NET中有3个不同的定时器.所以正好研究研究.这3个定时器分别是: //1.实现按用户定义的时间间隔引发事件的计时器.此计时器最宜用于 Windows 窗体应 ...
- uri中为什么本地文件file后面跟三个斜杠, http等协议跟两个斜杠?
那就要从URI[1]的结构来看了 scheme:[//[user:password@]host[:port]][/]path[?query][#fragment] 可以看到,如果有host的时候,前面 ...
- Linux解压/压缩命令——tar、gz、tar.gz、tgz、bz2、tar.bz2、Z、zip、rar、lha
.tar 解包:tar -xvf FileName.tar 打包:tar -cvf FileName.tar DirName ——————————————— .gz 解压1:gunzip FileNa ...
- hive-安装0.13.1(hadoop2.2.0)
hadoop2.2.0 hive0.13.1 (事先已经安装好hadoop.MySQL以及在MySQL中建好了hive专用账号,数据创建不创建都可以) 1.下载解压 2.把MySQL驱动加入hive的 ...
- IIS 之 添加绑定域名 或 设置输入IP直接访问网站
1.打开IIS,右键站点 → 编辑绑定,弹出“网站绑定”窗口,如下图: 2.点击“添加”,弹出“添加网站绑定”窗口,如下图: 注意:若想输入 IP 地址直接访问,则可以有以下两种设置任一均可: ...
- 深入理解windows
阿猫翻译的,用作备忘 深入理解windows——session.window stations.desktops 翻译自:http://www.brianbondy.com/blog/id/100/ ...
- 大文件读取方法(C#)
之前都是用StreamReader.ReadLine方法逐行读取文件,自从.NET4有了File.ReadLines这一利器,就再也不用为大文件发愁了. File.ReadLines在整个文件读取到内 ...
- 移植最新u-boot(裁剪和修改默认参数)之韦东山笔记
1.下载.建立source insight工程.编译.烧写.如果无运行分析原因 tar xjf u-boot-2012.04.01.tar.bz2 cd u-boot-2012.04.01 make ...