1

我正在使用 Castle Active Record 进行项目。今天我偶然发现了 AR 协会的“Insert = true”属性参数,但我无法确定它的实际作用。

[BelongsTo("UserId",Insert = true)]
public ARUser User {
  get { return mUser; }
  set { mUser = value; }
}

有人可以给我一个线索吗?我在文档中找不到答案。

4

2 回答 2

4

是的,您会在一些 AR 属性上找到 Insert 和 Update 属性。

我必须做一些测试以确保我理解文档。

将 Update 和 Insert 都设置为 false 表示该属性将对您的数据库访问是只读的(使用公共 setter 可能会令人困惑。)

[Property(Insert=false, Update=false)]
public virtual string Name { get; set; }

将 update 设置为 true 并将 insert 设置为 false 表示设置此属性然后插入元素不会在数据库中设置该值。

[Property(Insert=false)]
public virtual DateTime Created { get; set; }

至于使用场景,就靠你自己了。

于 2009-02-04T02:32:17.200 回答
0

来自文档- 设置为 false 以在插入此 ActiveRecord 类的实体时忽略此关联。

于 2009-02-04T02:20:49.187 回答