views:

16

answers:

1
var user = new User()
{
    Username = "a",
    Password = "b",
};

user.Save();

Console.WriteLine(user.ID)         // prints "504"
Console.WriteLine(user.IsLoaded()) // prints "false"

If the ID property is automatically set on Save(), I would expect IsLoaded() to also be set (to true). Why is it my responsibility to call user.SetIsLoaded(true);?

(I realize I can just edit ActiveRecord.tt to get this working, but maybe I just don't understand what IsLoaded() actually represents.)

A: 

IsLoaded states that the record you are looking at represents data in the database. This is for example used to detect that a record is dirty. IsLoaded == false records cannot get dirty because they do not represent data in the database. IsLoaded == true does, so changing properties on such a record sets it dirty and you can save the record again.

http://stackoverflow.com/questions/1402187/subsonic-3-save-then-update also describes some details on this.

Pieter