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 ...
随机推荐
- Codeforces Round #329 (Div. 2) D. Happy Tree Party 树链剖分
D. Happy Tree Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/p ...
- 2015南阳CCPC C - The Battle of Chibi DP
C - The Battle of Chibi Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Cao Cao made up a ...
- 为TListBox添加水平滚动条
为TListBox添加水平滚动条 实例说明 TListBox组件是一个较为常用的列表组件,在默认情况下该组件是没有水平滚动条的,所以文字过长会显示不完全,在文字较短的情况下还可以,但是如果一行的文字很 ...
- python选择排序
def select_sort(list): for i in range(len(list)): position = i for j in range(i,len(list)): if list[ ...
- Web之真假分页
在web设计中一个无法避免的问题就是分页显示.当数据量特别大的时候,我们不可能将全部的数据都在一个页面进行显示,假设这样将严重影响到它的美观性.所以在这个时候,分页显示则成为了我们的大功臣.当然分页也 ...
- 【虚拟化实战】VM设计之一vCPU
作者:范军 (Frank Fan) 新浪微博:@frankfan7 虚拟机需要多少个vCPU呢?是不是个数越多性能越好呢?这方面存在着很多误区.给VM配置CPU资源的时候,要精打细算才能最大可能的利用 ...
- VBA Excel 打印
1. 设置 页边距.打印区域 With .PageSetup .HeaderMargin = Application.CentimetersToPoints(0.5) .LeftMargin = Ap ...
- 利用mmap /dev/mem 读写Linux内存
转载:http://blog.csdn.net/zhanglei4214/article/details/6653568 使用 hexedit /dev/mem 可以显示所有物理内存中的信息. 运用m ...
- MII、RMII、GMII接口的详细介绍
转载:http://blog.csdn.net/reille/article/details/6312156 概述: MII (Media Independent Interface(介质无关接口)或 ...
- 使用 Feedly RSS阅读器订阅技术大牛的博客
这几天一直都在自己看书,可是书上面的东西都比较落后一点,而且没有大牛博文上的东西讲的深入,可是来回跳转各位大牛的博客又非常的麻烦,有一些公众账号虽然也会推荐一些知识内容,可是你应该有过看到多个公众号发 ...