0

Is it possible to ignore a value while using AddOrUpdate?

Also, what values does it look for when matching to a value and deciding what to change. I tried reading this article, but obviously it didn't help.

Let's say I have two objects in db (I realize this isn't real code):

Obj1.fieldA == 1, Obj1.fieldB == 2, Obj1.fieldC == 5
Obj1.fieldA == 1, Obj1.fieldB == 3, Obj1.fieldC == 6

And then I try to AddOrUpdate an object that matches both:

Obj3.fieldA == 1, Obj3.fieldB == 2, Obj3.fieldC == 6

How is it going to decide which one to update, if any/both?

Edit based on comments/answers in regard to Id, which I don't specify.

var someGroup = new API.Models.Group
                {
                    Name = "Blah"
                    Organization = "Blabedy blah",
                    Description = "Blah blah"
                }

db.Groups.AddOrUpdate(someGroup);

The id property is there but automatically generated:

// Id
[Key]
public long Id { get; set; }
VSO
  • 11,546
  • 25
  • 99
  • 187
  • "Is it possible to ignore a value while using AddOrUpdate?" - I have no idea what this means. Please explain better. – D Stanley Nov 10 '15 at 22:35
  • If you are asking how to handle primary/natural keys - have a look at this answer - http://stackoverflow.com/a/17719137/150342 – Colin Nov 11 '15 at 13:15

1 Answers1

2

How is it going to decide which one to update,

It will update the record with the matching primary key. For example, if the primary key is a compound key consisting of fieldA and fieldB then it will match the first records and update fieldC

D Stanley
  • 149,601
  • 11
  • 178
  • 240