官方开发指导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方法 ,应该是给绑定数据源传值的,测试使用的时候并没有效果,传递多个值理论是使用的数组。问题未解决。

最新文章

  1. [Android] ListView关于adapter多种view设置
  2. selenium 富文本框处理
  3. C#学习笔记-----基于AppDomain的&quot;插件式&quot;开发
  4. 老是出现dispolse 找不到合适的方法来重写
  5. WPF多线程UI更新——两种方法
  6. 转 XMLHttpRequest().readyState的五种状态详解
  7. RIME输入法
  8. centos6.5搭建vpn服务器
  9. 微信分组群发45028,微信分组群发has no masssend quota hint
  10. [Mugeda HTML5技术教程之6]添加元素
  11. 使用stackOfIntegers实现降序素数
  12. HIbernate实体类注解配置
  13. linux环境下根据文件的某一列进行去重
  14. 细谈最近上线的Vue2.0项目(一)
  15. 【NOIP2013】华容道 广搜+spfa
  16. Windows下MySQL重装引起问题的解决
  17. sha-hmac
  18. asp.net c#并行调用service层代码
  19. Go语言之高级篇beego框架之model设计构造查询
  20. The Little Prince-12/06

热门文章

  1. HDU 1863 畅通工程
  2. delphi 05 图片和超链接
  3. C# Func&amp;lt;&amp;gt;托付
  4. js中substr与substring的差别
  5. MySQL &#183; 引擎特性 &#183; InnoDB 事务子系统介绍
  6. 浅谈Linux的内存管理机制
  7. BI之ETL学习(一)kettle
  8. Ng-include 例子
  9. document.body.clientHeight与document.documentElement.clientHeight
  10. Android(java)学习笔记73:线程组的概述和使用