views:

125

answers:

1

This method works fine:

Person p = new Person(3);
p.Name = "Bob";
p.Update();

However if I have an IQueryable foreign key collection the below fails

var foreignItems = Person.Find(x => x.ID == 3)
foreach(Person p in foreignItems)
{
  p.Name = "Bob";
  p.Update(); /*THROWS EXCEPTION */
}

Exception is thrown in Repository Update as it executes a query from BuildUpdateQuery such as - UPDATE PERSON WHERE ID = {0} which is wrong syntax!

A: 

This looks like a bug, you should report it to github (the new host for SubSonic source). In the meantime does calling p.Save() may work around the issue.

Adam
p.Save() calls Update() in ActiveRecord
Jon
So do you get the same exception when calling save?
Adam
No because it does an Add which is wrong. It seems if in that loop you then say var item = new Person(p.ID); item.Save it all works but you shouldnt have to create a new instance of the object if you have a list of them instantiated by the Find method
Jon