为什么 Save() 时 IsLoaded 不设置为 true?

发布于 2024-09-30 01:04:02 字数 479 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

棒棒糖 2024-10-07 01:04:02

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文