[
https://issues.apache.org/jira/browse/IGNITE-5298?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16096367#comment-16096367
]
Sergey Stronchinskiy commented on IGNITE-5298:
----------------------------------------------
Hi [~ptupitsyn],
I've looked around a little bit and found few approaches to work around similar
issues:
1. First approach is to pass an object initializer in to update method like
this:
{code} persons.Where(x => x.Key > 10).UpdateAll(x => new Person{ OrgId = 42,
Name = "Foo"}){code}
with signature of {{UpdateAll}} like {{public static int UpdateAll<TKey,
TValue>(this IQueryable<ICacheEntry<TKey, TValue>> query,
Expression<Func<TValue, TValue>> update)}}
For me it seems most clear and clean API but it has two drawbacks - if class
has no parameterless constructor user will need to provide some dummy values
which will not be actually parsed into SQL and if property has no public
setter, then it would be impossible to update them.
2. {{Moq}} framework has an option to set properties of mocked object and uses
{{==}} sign instead of {{=}} to achieve that:
{code}
Mock.Of<Person>( x => x.Name == "Foo" && x.OrgId = 42);
{code}
Also there is an option which you suggested.
As for me i think first API is the way to go, cause second one is not that
clear and the one from your suggestion will add a method with a signature which
can be applied to anything and will be shown in intellisense suggestions to
often. As for the restrictions of the API we can overcome them with extra
method like:
{code}
persons.Where(x => x.Key > 10).UpdateAll(x => new { x.OrgId, x.Name,
AddressName = x.Address.Name }, new { OrgId = 42, Name = "Foo", AddressName =
"Bar"});
{code}
> .NET: DML update via LINQ
> -------------------------
>
> Key: IGNITE-5298
> URL: https://issues.apache.org/jira/browse/IGNITE-5298
> Project: Ignite
> Issue Type: New Feature
> Components: platforms
> Affects Versions: 2.1
> Reporter: Pavel Tupitsyn
> Assignee: Sergey Stronchinskiy
> Labels: .NET, LINQ, important
>
> Bulk update with LINQ:
> {code}
> var persons = ignite.GetCache<int, Person>("persons").AsCacheQueryable();
> int affectedRows = persons.Where(x => x.Key > 10).UpdateAll(x =>
> x.Value.OrgId = 7);
> {code}
> See bulk delete with {{RemoveAll}}, IGNITE-4904.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)