日常开发之中,列表与独立的实体对象操作,是一样的重要,在XPO中是通过XpoCollection来管理的,Gentle里面又是什么样子呢?

      根据Gentle的文档中的示例如下:
  

Gentle.NET笔记(二)-列表示例static public IList ListAll
{

Gentle.NET笔记(二)-列表示例        }

    这是一个返回所有对象的方法,采用的是一个静态函数。

  如果需要自定义返回的对象,采用的方法则是:

static public IList ListByNameStartsWith( string partialName )
{
    SqlBuilder sb = new SqlBuilder( StatementType.Select, typeof(User) );
    
    //注意:partialName参数必须包含%,以用于Sql server中的Like 的查询。
    sb.AddConstraint( Operator.Like, "Name", partialName );
   
    // passing true indicates that we'd like a list of elements, i.e. that no primary key
    // constraints from the type being retrieved should be added to the statement
    SqlStatement stmt = sb.GetStatement( true );    

    //执行statement/query的并且根据返回结果创建一个User实例的集合。
    return ObjectFactory.GetCollection( typeof(User), stmt.Execute() );
}

相关文章:

  • 2021-08-21
  • 2021-12-29
  • 2021-11-29
  • 2021-08-18
  • 2021-07-15
  • 2021-08-20
  • 2022-02-09
  • 2022-02-12
猜你喜欢
  • 2022-01-30
  • 2021-06-27
  • 2021-11-05
  • 2021-06-05
  • 2021-08-14
  • 2021-12-18
  • 2022-12-23
相关资源
相似解决方案