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 ...
随机推荐
- URAL 2048 History 蔡勒公式
HistoryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...
- linux对外开放某个端口命令
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /etc/rc.d/init.d/iptables save /etc/rc.d/init.d/ ...
- [Ramda] Compose and Curry
Curry: The idea of Curry is to spreate the data from the function. Using Curry to define the functio ...
- 玩转Bash脚本:test測试语句
总第1篇test就是測试的意思,经常使用在流程控制语句中作为条件.以下做一下介绍. 关于真值 与其它语言不同,Bash(包含其它Shell)中,是用0表示真,非0表示假的.之所以用0表示成功,而不是1 ...
- C语言--enum,typedef enum 枚举类型详解
原文:http://z515256164.blog.163.com/blog/static/32443029201192182854300/ 有改动 C语言详解 - 枚举类型 注:以下全部代码的执行环 ...
- SHELL 详解
http://blog.csdn.net/vah101/article/details/6173488 ( a=2;b=4;c=9; ) 子shell 环境 { a=2;b=4;c=9; } 当前sh ...
- 【ZZ】Python入门神图
http://mp.weixin.qq.com/s?__biz=MzA3OTIxNTA0MA==&mid=401383338&idx=1&sn=73009cce06d58656 ...
- ng中用$http接后台接口的异步坑
最近笔者在一个项目中用ng去接后台的接口.因为前后端都是新手,前端的不懂后台,且没有经验:后端的不懂前端,也没有经验,然后接口bug百出,文档写得乱.一个接口,后台改了三次,我也是寸步难行. 首先来看 ...
- 双向BFS
转自“Yuan” 如果目标也已知的话,用双向BFS能很大提高速度 单向时,是 b^len的扩展. 双向的话,2*b^(len/2) 快了很多,特别是分支因子b较大时 至于实现上,网上有些做法是用两个 ...
- Oracle 版本查看及版本号说明
http://blog.163.com/magicc_love/blog/static/185853662201210194592757/ select * from v$version; 或sele ...