How can I add a value to Fields of Type Entity when using App.Data.Create()

最后都变了- 提交于 2021-01-29 06:06:10

问题


When I am in external code and trying to add an entry to an existing Content Type, how can add one or more values to a field of type Entity? So lets use the FAQ v3 app as an example, here is the code with the add Categories line commented out:

    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);
    }

I need the new Question to start life already in a Category named "Un-answered" which is EntityId 1111.


回答1:


This is very simple. Just add a List<int> or List<Guid> as that field with the property. Something like

fields.Add("Category", new List<int> { 1111 });


来源:https://stackoverflow.com/questions/64306880/how-can-i-add-a-value-to-fields-of-type-entity-when-using-app-data-create

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!