gpt4 book ai didi

c# - 在数据库中存储动态JSON数据并通过键值搜索

转载 作者:太空宇宙 更新时间:2023-11-03 14:49:35 29 4
gpt4 key购买 nike

<分区>

我需要在数据库中存储动态 json 并通过键值搜索

我有json

    [{
"id": 1,
"Type": "string",
"FieldName" : "Test",
"Value": "Test",
}, {
"id": 2,
"Type": "bool",
"FieldName" : "Test2",
"Value": "true",
"id": 2,
"Type": "dropdown",
"FieldName" : "dropDownTest",
"Value": [{"text":"my placeholder", "Value": "myTestValue"}, {"text":"my placeholder2", "Value": "myTestValue2"}]
},
{
"id": 3,
"Type": "int",
"Value": 133
},
{
"id": 4,
"Type": "DateTime",
"Value": ""
}]

此 json 由管理站点生成。管理员有一个面板,他可以在其中添加列、字段类型和默认值(如果是下拉列表,则为值数组)

这个json转换为表单,用户在网站上填写并存储到数据库

保存的数据是这样的:

   [{
"QuestionId": 1,
"Value": "Test",
},
{
"QuestionId": 2,
"Value": true,
},
{
"QuestionId": 4,
"Value": "true",
"Value": "2018-09-16T20:03:57.551Z"
}
]

任务:

  1. 在数据库中存储用户的答案
  2. 在数据库中按答案搜索(现场过滤,一个或多个匹配项,例如问题 1 和 4 匹配项(值为“测试”,日期晚于昨天...))
  3. 快速搜索的最佳结构

我的愿景:创建实体

public class QuestionEntity
{
public int id { get; set; }
public string Type { get; set; }
public string FieldName { get; set; }
public string Value { get; set; }
}

并创建一个答案实体

public class Answer
{
public int QuestionId { get; set; }
public string Value { get; set; }
}

并将此答案添加为用户集合

public ICollection<Answer> Answers{get; set;}

我不确定这项任务的最佳方式是什么,如果有人分享他们的案例,我将不胜感激。

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com