【发布时间】:2014-11-26 09:47:13
【问题描述】:
我已使用与内容类型同名的部分将名为 Website 的 LinkField 添加到内容类型。
ContentDefinitionManager.AlterTypeDefinition("MyContentType", a => a
.WithPart("CommonPart")
.WithPart("MyContentType")
.Creatable());
ContentDefinitionManager.AlterPartDefinition("MyContentType", cft => cft
.WithField("Website", a => a.OfType("LinkField").WithDisplayName("Website")
.WithSetting("FieldIndexing.Included", "True"))
.Attachable());
然后,我会在迁移期间创建一些默认内容项。
我在添加字段数据之前创建项目,因为在创建项目之前设置字段值时,我遇到了字段未更新的问题。 (请随意阐明这一点,但这不是我的问题)
var myItem = _orchardServices.ContentManager.New("MyContentType");
_orchardServices.ContentManager.Create(myItem);
var websitePart = myItem.Parts.FirstOrDefault(x => x.Fields.Any(y => y.Name == "Website"));
var websiteLinkField = websitePart .Fields.FirstOrDefault(x => x.Name == "Website") as LinkField;
websiteLinkField.Value = "http://www.google.com";
websiteLinkField.Text = "Link to google";
_orchardServices.ContentManager.Publish(myItem);
我意识到有更多动态的方法可以访问该字段,但这似乎也有效。
当我查看项目时会显示数据,但随后我会继续进行查询。
我使用 UI 构建了一个简单的查询,在 LinkField 的文本中查找单词“google”,然后点击预览。
没有找到结果。
然后我打开从迁移中创建的项目之一,然后简单地点击“保存”按钮。
然后我再次尝试预览,我现在保存的项目出现了。
据我所知,当我保存一个我没有从迁移中执行的内容项时,正在发生一些事情。但是我一直在遍历各个角度的代码,但我找不到它。 我怀疑也许应该触发一些处理程序以创建 FieldIndex'es ? (我知道如何触发 Lucene 索引的更新,但正如人们所期望的那样,它不会影响使用 Projections 模块查询字段,我现在真的迷路了。)
现在我只是在黑暗中盲目地刺伤。
真的很感激我能得到的任何帮助,即使它只是让我回到正确的方向。谢谢。
【问题讨论】:
标签: c# orchardcms orchardcms-1.8