@@ -474,7 +474,7 @@ IList<Cat> oldCats =
474
474
Beginning with NHibernate 5.0, Linq queries can be used for inserting, updating or deleting entities.
475
475
The query defines the data to delete, update or insert, and then <literal >Delete</literal >,
476
476
<literal >Update</literal > and <literal >Insert</literal > queryable extension methods allow to delete it,
477
- or instruct in which way it should updated or inserted. Those queries happen entirely inside the
477
+ or instruct in which way it should be updated or inserted. Those queries happen entirely inside the
478
478
database, without extracting corresponding entities out of the database.
479
479
</para >
480
480
<para >
@@ -487,7 +487,7 @@ IList<Cat> oldCats =
487
487
<para >
488
488
<literal >Insert</literal > method extension expects a NHibernate queryable defining the data source of
489
489
the insert. This data can be entities or a projection. Then it allows specifying the target entity type
490
- to insert, and how to convert source data to those target entities. Two forms of target specification
490
+ to insert, and how to convert source data to those target entities. Three forms of target specification
491
491
exist.
492
492
</para >
493
493
<para >
@@ -497,6 +497,13 @@ IList<Cat> oldCats =
497
497
.Where(c => c.BodyWeight > 20)
498
498
.Insert()
499
499
.As(c => new Dog { Name = c.Name + "dog", BodyWeight = c.BodyWeight });]]> </programlisting >
500
+ <para >
501
+ Projections can be done with an anonymous object too, but it requires supplying explicitly the target type:
502
+ </para >
503
+ <programlisting ><![CDATA[ session.Query<Cat>()
504
+ .Where(c => c.BodyWeight > 20)
505
+ .Insert()
506
+ .As<Dog>(c => new { Name = c.Name + "dog", BodyWeight = c.BodyWeight });]]> </programlisting >
500
507
<para >
501
508
Or using assignments:
502
509
</para >
@@ -507,7 +514,7 @@ IList<Cat> oldCats =
507
514
.Set(d => d.Name, c => c.Name + "dog")
508
515
.Set(d => d.BodyWeight, c => c.BodyWeight));]]> </programlisting >
509
516
<para >
510
- In both cases, unspecified properties are not included in the resulting SQL insert.
517
+ In all cases, unspecified properties are not included in the resulting SQL insert.
511
518
<link linkend =" mapping-declaration-version" ><literal >version</literal ></link > and
512
519
<link linkend =" mapping-declaration-timestamp" ><literal >timestamp</literal ></link > properties are
513
520
exceptions. If not specified, they are inserted with their <literal >seed</literal > value.
@@ -523,7 +530,7 @@ IList<Cat> oldCats =
523
530
<para >
524
531
<literal >Update</literal > method extension expects a queryable defining the entities to update.
525
532
Then it allows specifying which properties should be updated with which values. As for
526
- <literal >Insert</literal >, two forms of target specification exist.
533
+ <literal >Insert</literal >, three forms of target specification exist.
527
534
</para >
528
535
<para >
529
536
Using projection to updated entity:
@@ -532,6 +539,13 @@ IList<Cat> oldCats =
532
539
.Where(c => c.BodyWeight > 20)
533
540
.Update()
534
541
.As(c => new Cat { BodyWeight = c.BodyWeight / 2 });]]> </programlisting >
542
+ <para >
543
+ Projections can be done with an anonymous object too:
544
+ </para >
545
+ <programlisting ><![CDATA[ session.Query<Cat>()
546
+ .Where(c => c.BodyWeight > 20)
547
+ .Update()
548
+ .As(c => new { BodyWeight = c.BodyWeight / 2 });]]> </programlisting >
535
549
<para >
536
550
Or using assignments:
537
551
</para >
@@ -541,7 +555,7 @@ IList<Cat> oldCats =
541
555
.Assign(a => a
542
556
.Set(c => c.BodyWeight, c => c.BodyWeight / 2));]]> </programlisting >
543
557
<para >
544
- In both cases, unspecified properties are not included in the resulting SQL update. This could
558
+ In all cases, unspecified properties are not included in the resulting SQL update. This could
545
559
be changed for <link linkend =" mapping-declaration-version" ><literal >version</literal ></link > and
546
560
<link linkend =" mapping-declaration-timestamp" ><literal >timestamp</literal ></link > properties:
547
561
using <literal >UpdateVersioned</literal > instead of <literal >Update</literal > allows incrementing
0 commit comments