博客园中转

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

Find and FindAll

More complex criteria can be expressed using the Find and FindAll methods, which accept an expression, kind of similar to LINQ. Except not LINQ.

Simple.Data:

db.Users.Find(db.Users.JoinDate <= “2010-01-01”)

SQL:

SELECT * FROM [Users] WHERE [Users].[JoinDate] <= @p1

Criteria can be combined using the && and || operators. Parentheses for altering grouping of expressions are supported:

Simple.Data:

db.Users.Find(db.Users.Active.Like(“Y”) && db.Users.JoinDate <= “2010-01-01”)

SQL:

SELECT * FROM [Users] WHERE ([Users].[Active] LIKE @p1 AND [Users].[JoinDate]) <= @p2

Supported operators for Find

  • ==
  • !=
  • <
  • <=
  • >
  • >=

 

 

Joins

If you have referential integrity set up, Simple.Data will automatically apply joins for Find operations which use sub-object style criteria. Like this:

Simple.Data:

db.Customers.Find(db.Customers.Invoices.Paid == “N”)

SQL:

SELECT [Customers].* FROM [Customers] 
JOIN [Invoices] ON [Customers].[CustomerId] = [Invoices].[CustomerId]
WHERE [Invoices].[Paid] = @p1

Getting all the data

You can use the All method to return all the data from a table:

Simple.Data:

db.Users.All()

SQL:

SELECT * FROM Users

Like FindAllBy it returns an IEnumerable<dynamic>.

 

posted on 2012-04-29 08:54  pieux  阅读(709)  评论(0编辑  收藏  举报