“Insert = true”是什么意思? Castle Active Record Association 的意思
我正在开发一个使用 Castle Active Record 的项目。 今天我在 AR 关联上偶然发现了“Insert = true”属性参数,但我无法弄清楚它实际上是做什么的。
[BelongsTo("UserId",Insert = true)]
public ARUser User {
get { return mUser; }
set { mUser = value; }
}
有人可以给我线索吗? 我在文档中找不到答案。
I am working on a project using Castle Active Record. I stumbled across the "Insert = true" attribute argument on the AR association today, but I couldnt workout what it actually does.
[BelongsTo("UserId",Insert = true)]
public ARUser User {
get { return mUser; }
set { mUser = value; }
}
Can someone give me a clue? I couldn't find the answer in the documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您会在一些 AR 属性上找到插入和更新属性。
我必须做一些测试以确保我理解文档。
将 Update 和 Insert 设置为 false 表示该属性对于数据库访问来说是只读的(使用公共 setter 这可能会造成混乱。)
将 update 设置为 true 并将 insert 设置为 false 表示设置此属性然后插入元素将不在数据库中设置该值。
至于使用场景,就看你自己了。
Yep, you'll find the Insert and Update property on a few AR attributes..
I had to do a little testing to make sure I understood the documentation.
Having both Update and Insert set to false indicates that the property will be readonly to your database access (with a public setter this could get confusing.)
Having update set to true and insert to false indicates that setting this property and then inserting the element will not set that value in the database.
As for usage scenarios, you're on your own.
来自 文档 - 设置为 false 以忽略此设置插入此 ActiveRecord 类的实体时关联。
From the documentation - Set to false to ignore this association when inserting entities of this ActiveRecord class.