MightyOrm / Mighty

A new, small, dynamic micro-ORM. Highly compatible with Massive, but with many essential new features.
BSD 3-Clause "New" or "Revised" License
101 stars 20 forks source link

Update documentation to reflect use of UpdateUsing #24

Open KeishaW opened 4 years ago

KeishaW commented 4 years ago

I was attempting to do an update as described in the docs:

var db = new MightyOrm(connectionString, "Person",  "PersonID");
var p = db.Single(42); // get from Person table by primary key
p.LoyalCustomer = true;
db.Update(p);

But I got this error: Cannot complete UPDATE operation, you must provide a WHERE value (specify 1=1 to affect all rows)

Looking at the Update methods, there seems to be no parameter for where .

Digging further into the Issues here lead me to this closed issue about UpdateUsing which seems to work.

Could the documentation be updated to specify using UpdateUsing instead of just Update as this does not seem to work?

mikebeaton commented 4 years ago

UpdateUsing is what you should be using if you want to specify a where clause but the example you show shouldn't need a where clause: the object has a primary key and the instance of MightyOrm knows which the primary key field is.

The only thing I can think of is, are you sure you have the equivalent of , "PersonID"); in your own code? If not, Mighty won't know what the PK is and so it may be giving that (misleading) error message because of that.

Let me know about that, and I'll try to make some time to look into it some more ... if it is what I am suggesting, then I should probably figure out a way to specify that providing a primary key field would also have solved the problem, in those cases where it would (which IIRC unfortunately isn't all of the cases where that error message can show up!).