为什么 Save() 时 IsLoaded 不设置为 true?
var user = new User()
{
Username = "a",
Password = "b",
};
user.Save();
Console.WriteLine(user.ID) // prints "504"
Console.WriteLine(user.IsLoaded()) // prints "false"
如果 ID
属性在 Save()
上自动设置,我希望 IsLoaded()
也被设置(为 true< /代码>)。为什么我有责任调用
user.SetIsLoaded(true);
?
(我意识到我可以编辑 ActiveRecord.tt
来使其工作,但也许我只是不明白 IsLoaded()
实际代表什么。)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IsLoaded
表明您正在查看的记录代表数据库中的数据。例如,这用于检测记录是否脏。IsLoaded == false
记录不会变脏,因为它们不代表数据库中的数据。IsLoaded == true
确实如此,因此更改此类记录的属性会将其设置为脏,您可以再次保存该记录。Subsonic 3 Save() then Update()? 也描述了这方面的一些细节。
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.Subsonic 3 Save() then Update()? also describes some details on this.