You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//get the customer with all nested data and execute the above query too
206
+
varcustomer=await_dbContext.Customers.GetMany(customerIds)//returns a wrapper to configure the query
207
+
.Include(c =>c.Addresses.Single().Country,//include Addresses in the result using the fastest approach: join, new query, batch fetch. Usage: c.Child1.ChildList2.Single().Child3 which means include Child1 and ChildList2 with ALL Child3 properties
208
+
c =>c.PhoneNumbers.Single().PhoneNumberType,//include all PhoneNumbers with PhoneNumberType
209
+
c =>c.Cart.Products.Single().Colors)//include Cart with Products and details about products
210
+
.Unproxy()//instructs the framework to strip all the proxy classes when the Value is returned
211
+
.ListAsync(token);//this is where the query(s) get executed
212
+
213
+
returnOk(customer);
214
+
}
215
+
189
216
/// <summary>
190
217
/// A simple example of projecting a query
191
218
/// </summary>
@@ -275,14 +302,26 @@ public async Task<IActionResult> TestMultipleQueries(CancellationToken cancellat
275
302
});
276
303
}
277
304
305
+
/// <summary>
306
+
/// Increase price by 5 for all products that are cheaper than 100 without loading them in memory.
Copy file name to clipboardExpand all lines: README.md
+67-12Lines changed: 67 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,7 +69,7 @@ public DbContext(ISessionFactory sessionFactory) : base(sessionFactory) {
69
69
70
70
## Eager loading
71
71
Using lambda expressions you can specify which child properties should be populated. The framework will determine the fastest approach to load the data: using join, future queries or by using batch fetching.
72
-
Depending on the number of returned rows and the depth you might need to finetune your queries, but in most of the cases the framework takes the best decision.
72
+
Depending on the number of returned rows and the depth you might need to finetune your queries, but in most cases the framework takes the best decision.
73
73
74
74
```csharp
75
75
varcustomer=await_dbContext.Customers.Get(customerId) //returns a wrapper to configure the query
@@ -85,7 +85,7 @@ The expression `c.Addresses.Single().Country` will load all the nested child obj
85
85
86
86
87
87
## Unproxy
88
-
You can use IUnitOfWork.Unproxy, ISingleEntityWrapper.Unproxy or IEntityListWrapper.Unproxy
88
+
You can use Unproxy from IUnitOfWork, ISingleEntityWrapper, IMultipleEntityWrapper or IEntityListWrapper
89
89
90
90
```csharp
91
91
varcustomer=await_dbContext.Customers
@@ -98,23 +98,46 @@ An unproxied object will contain the foreign key ids (One to One and Many to One
98
98
For example in the above query the Cart property will be instantiated and popuplated with the Id field.
99
99
100
100
101
-
## Multi Queries
101
+
## Deferred Execution
102
102
Using `Deferred()` you can execute multiple queries in a single server trip.
103
103
Bellow is an example with 3 different queries that get executed in one server trip.
varprodCount=awaitprodCountP.ValueAsync(); //returns value
117
-
varexpProds=awaitexpProdsP.ListAsync(); //returns value
116
+
varcustomer=await_dbContext.Customers
117
+
.Get(customerId)
118
+
.Deferred()
119
+
.ValueAsync();
120
+
varprodCount=awaitprodCountP.ValueAsync(); //returns one value
121
+
varexpProds=awaitexpProdsP.ListAsync(); //returns list
122
+
```
123
+
124
+
125
+
## Conditional Queries
126
+
If you need to update or delete a set of records that meet a condition, you don't need to load them in memory. Just write an expression and it will be evaluated immediately.
127
+
You should always run your commands inside a transaction with `BeginTransaction()` and `CommitTransactionAsync`.
128
+
129
+
### UpdateWhereAsync
130
+
Increase price by 5 for all products that are less than 100, without loading them in memory.
0 commit comments