问题描述
当我使用外部代码并尝试将条目添加到现有“内容类型”时,如何将一个或多个值添加到“实体”类型的字段中?因此,以FAQ v3应用程序为例,这是添加类别行被注释掉的代码:
int appId = 4; // FAQ3 for me
var appx = ToSic.Sxc.Dnn.Factory.App(appId);
var fields = new Dictionary<string,object>();
fields.Add("InternalTitle",askQ.Name + "," + askQ.Email);
fields.Add("Question",askQ.Question);
// fields.Add("Categories",""); // what is the Syntax to set 1 category = Entityid 1111?
try
{
appx.Data.Create("Question",fields);
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError,ex.Message);
}
我需要新问题才能在名为“ Un-answered”的类别(即EntityId 1111)中开始生活。
解决方法
这很简单。只需在属性中添加List<int>
或List<Guid>
作为该字段即可。像
fields.Add("Category",new List<int> { 1111 });