Hi Thierry,
That's not a problem. Only the properties/columns included in the member
initialization will be included in the update query, i.e
session.Query<Animal>()
.Where(x=>x.Age>3)
.Update(x => new Animal {
Name = "Peter",
Age = x.Age+1,
});
will result in
update Animal set Name='Peter',Age=Age+1
2015-01-07 23:01 GMT+01:00 Thierry Lach <[email protected]>:
> Sorry about coming late to the party, but if you use
>
> session.Query<Animal>()
> .Where(x=>x.Age>3)
> .Update(x => new Animal {
> Name = "Peter",
> Age = x.Age+1,
> });
>
> how will you be able to tell when a field needs to be set to null, as the
> default of an uninitialized field would also be null?
>
> I also don't see how you could recognize that a non-nullable numeric field
> was _not_ being updated, as in:
>
> session.Query<Animal>()
> .Where(x=>x.Age>3)
> .Update(x => new Animal {
> Name = "Peter",
> });
>
>
>
>
> On Thu, Jan 1, 2015 at 11:17 AM, Gunnar Liljas <[email protected]>
> wrote:
>
>> https://github.com/nhibernate/nhibernate-core/pull/391
>>
>> 2014-12-19 17:46 GMT+01:00 Patrick Earl <[email protected]>:
>>
>>> In our shop we use interfaces for entities exclusively since we have a
>>> system that allows for complex inheritance. It would be sad to not have
>>> support for interfaces or limited constructor scenarios.
>>>
>>> What's at the heart the statement that executes? If it's just a matter
>>> of setting individual columns perhaps the syntax should reflect that more
>>> than pretending like your C# constructor code is going to be called. Doing
>>> it on individual properties allows for interfaces, doesn't incorrectly
>>> imply that C# code is going to run on insert, and doesn't require the
>>> availability of an empty public constructor on a concrete type.
>>>
>>> Patrick Earl
>>> On Dec 18, 2014 6:02 PM, "Gunnar Liljas" <[email protected]>
>>> wrote:
>>>
>>>> Yes...
>>>>
>>>> session.Query<Animal>()
>>>> .Where(x=>x.Age>3)
>>>> .Update(x => new Animal {
>>>> Name = "Peter",
>>>> Age = x.Age+1,
>>>> });
>>>>
>>>> would work! Didn't think of that.
>>>>
>>>> I'm not completely sold on the "new Animal" part in an update. It looks
>>>> linguistically wrong. But it's certainly less verbose. The same problems as
>>>> for the Insert also applies.
>>>>
>>>> /G
>>>>
>>>>
>>>> 2014-12-19 1:54 GMT+01:00 Alexander Zaytsev <[email protected]>:
>>>>>
>>>>> What about this:
>>>>>
>>>>> session.Query<Animal>()
>>>>> .Where(x=>x.Age>3)
>>>>> .Update(x => new Animal {
>>>>> y.Name = "Peter",
>>>>> y.Age = y.Age+1,
>>>>> });
>>>>>
>>>>> ?
>>>>>
>>>>> On Fri, Dec 19, 2014 at 1:28 PM, Gunnar Liljas <
>>>>> [email protected]> wrote:
>>>>>>
>>>>>> Absolutely possible, but the (big) difference is that
>>>>>>
>>>>>> 1. An anonymous object will lose the static type relationship with
>>>>>> what you're updating/inserting, which kind of defeats the point of Linq
>>>>>> bulk operations.
>>>>>> 2. You will lose the possibility to express anything but simple value
>>>>>> expressions, i.e "SET FullName = FirstName + ' ' + LastName" (
>>>>>> Set(x=>x.FullName,x=>x.FirstName + " " + x.LastName), will not be
>>>>>> possible.
>>>>>>
>>>>>> /G
>>>>>>
>>>>>> 2014-12-19 1:20 GMT+01:00 Craig van Nieuwkerk <[email protected]>:
>>>>>>>
>>>>>>> Looks nice. But yes, I think if you can have anonymous object for
>>>>>>> the parameters this would be better. I have used FluentMigrator and it
>>>>>>> does
>>>>>>> this for Update/Insert pretty nicely.
>>>>>>>
>>>>>>> On Fri, Dec 19, 2014 at 11:13 AM, Alexander Zaytsev <
>>>>>>> [email protected]> wrote:
>>>>>>>>
>>>>>>>> Very nice. I would like to remove word "All" from the
>>>>>>>> operations.Also why do we need "Set" in update statement?
>>>>>>>>
>>>>>>>> On Fri, Dec 19, 2014 at 1:04 PM, Ricardo Peres <[email protected]>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Very nice! I implemented strongly typed delete in NH-3488
>>>>>>>>> <https://nhibernate.jira.com/browse/NH-3488>, but the syntax was
>>>>>>>>> a bit different:
>>>>>>>>>
>>>>>>>>> session.Delete<Product>(x => x.Price > 100);
>>>>>>>>>
>>>>>>>>> Do you have a pull request waiting to be issued?
>>>>>>>>>
>>>>>>>>> RP
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Thursday, December 18, 2014 11:21:06 PM UTC, Gunnar Liljas
>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> So, now I have completed and old abandoned NH project, to create
>>>>>>>>>> a Linq implementation of the bulk functionality. It's complete in
>>>>>>>>>> the sense
>>>>>>>>>> that all the unit tests from the HQL implementation passes with the
>>>>>>>>>> Linq
>>>>>>>>>> implementation as well, plus a couple more. Before I clean things
>>>>>>>>>> up, I'd
>>>>>>>>>> like you input on the syntax.
>>>>>>>>>>
>>>>>>>>>> Currently it works like this:
>>>>>>>>>>
>>>>>>>>>> Delete
>>>>>>>>>>
>>>>>>>>>> session.Query<Animal>()
>>>>>>>>>> .Where(x=>x.Age>3)
>>>>>>>>>> .DeleteAll();
>>>>>>>>>>
>>>>>>>>>> //all methods returns int (affected rows)
>>>>>>>>>>
>>>>>>>>>> Update
>>>>>>>>>>
>>>>>>>>>> session.Query<Animal>()
>>>>>>>>>> .Where(x=>x.Age>3)
>>>>>>>>>> .UpdateAll(x=>x
>>>>>>>>>> .Set(y=>y.Name,"Peter")
>>>>>>>>>> .Set(y=>y.Age,y=>y.Age+1)
>>>>>>>>>> )
>>>>>>>>>>
>>>>>>>>>> Insert (i.e INSERT SELECT)
>>>>>>>>>>
>>>>>>>>>> session.Query<Animal>()
>>>>>>>>>> .Where(x=>x.Age>3)
>>>>>>>>>> .InsertInto(x=>new Human{
>>>>>>>>>> Name=x.Name,
>>>>>>>>>> Age=x.Name+10
>>>>>>>>>> })
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> The Delete method was first implemented as
>>>>>>>>>> session.Delete<Animal>(x=>x.Age>3), but I added the
>>>>>>>>>> IQueryable<T>.DeleteAll extension for consistency.
>>>>>>>>>>
>>>>>>>>>> I welcome any ideas on how this can be improved/changed.
>>>>>>>>>>
>>>>>>>>>> /G
>>>>>>>>>>
>>>>>>>>> --
>>>>>>>>>
>>>>>>>>> ---
>>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>>> Groups "nhibernate-development" group.
>>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>>> send an email to
>>>>>>>>> [email protected].
>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>
>>>>>>>> --
>>>>>>>>
>>>>>>>> ---
>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>> Groups "nhibernate-development" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>> send an email to
>>>>>>>> [email protected].
>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>> ---
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "nhibernate-development" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>> send an email to [email protected]
>>>>>>> .
>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>> --
>>>>>>
>>>>>> ---
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "nhibernate-development" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>> --
>>>>>
>>>>> ---
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "nhibernate-development" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
>>>>
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "nhibernate-development" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "nhibernate-development" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "nhibernate-development" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> ---
> Facts do not cease to exist because they are ignored.
> *Aldous Huxley*
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nhibernate-development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
---
You received this message because you are subscribed to the Google Groups
"nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.