Simple.Data wiki 阅读 2

高宇定
2023-12-01

 

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 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/pieux/archive/2012/04/29/2475915.html

 类似资料: