官方开发指导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的使用的更多相关文章

  1. .Net程序员飞扬有用的85个工具

    1.Visual Studio Visual Studio Productivity Power tool:Visual Studio专业版(及以上)的扩展,具有丰富的功能,如快速查找,导航解决方案, ...

  2. 实用的VS工具

    工具 1.Visual Studio Visual Studio Productivity Power tool:Visual Studio专业版(及以上)的扩展,具有丰富的功能,如快速查找,导航解决 ...

  3. 对ASP.NET程序员非常有用的85个工具

    介绍 这篇文章列出了针对 ASP.NET 开发人员的有用工具. 工具 1. Visual Studio Visual Studio Productivity Power tool:Visual Stu ...

  4. 推荐几个对Asp.Net开发者比较实用的工具

    推荐几个对Asp.Net开发者比较实用的工具.大家有相关工具也可以在评论区留言,一起努力学习. 工具 1.Visual stdio Productivity Power tool:visual std ...

  5. .Net开发工程师工具箱

    Visual Studio Visual Studio Productivity Power tool:Visual Studio专业版(及以上)的扩展,具有丰富的功能,如快速查找,导航解决方案,可搜 ...

  6. asp.net 工具

    http://www.jb51.net/article/92465.htm 这篇文章列出了针对ASP.NET开发人员的有用工具. 工具 1.Visual Studio Visual Studio Pr ...

随机推荐

  1. Unix-Linux编程实践 学习点滴

    1.结构体最后定义一个char p[0]有什么作用 2. 3. 4. 1.结构体最后定义一个char p[0] 有什么作用 这是个广泛使用的常见技巧,常用来构成缓冲区.比起指针,用空数组有这样的优势: ...

  2. UVa572 Oil Deposits DFS求连通块

      技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...

  3. PostgreSQL的 initdb 源代码分析之十九

    继续分析: setup_dictionary(); 展开: 其中: cmd 是:"/home/pgsql/project/bin/postgres" --single -F -O ...

  4. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  5. 我总结的18个非常好用的vim指令

    在Linux下最有名的程序编辑器非vim莫属了. 在一般模式下, 1.dd——删除光标所在行 2./word ——全文搜索指定单词 3.G ——将光标移动到文件的最后一行,移动到第99行,就是99G ...

  6. POJ 3074 Sudoku (Dancing Links)

    传送门:http://poj.org/problem?id=3074 DLX 数独的9*9的模板题. 具体建模详见下面这篇论文.其中9*9的数独怎么转化到精确覆盖问题,以及相关矩阵行列的定义都在下文中 ...

  7. Python integer objects implementation

    http://www.laurentluce.com/posts/python-integer-objects-implementation/ Python integer objects imple ...

  8. css 设置全屏背景图片

    <div id="div1"><img src="img.jpg" /></div> div#div1{ position: ...

  9. 利用正则表达式作为string.split seprator

    某字符串 var str = "{1,att,7},{2,break,7},{3,crit,7},{4,combo,7},{5,break,7},{6,hit,7}"; 需要分割成 ...

  10. Linux shell 脚本攻略之文件查找与文件列表

    摘自:<Linux shell 脚本攻略>