我在 MongoDB 中有以下文档格式文件1:{ "_id" : ObjectId("5b0d30ae942267c0c8f6229d"), "Expression" : "[tag] = 'Druck1' && [status]='OK'", "Name" : "Druck1 is running", "Actions" : [ { "TemplateName" : "Warning", "Tags" : "[tag]", "Roles" : [ "Group_AdUser", "Group_FieldServiceCoordinator", "Group_FieldServiceTechnician", "Group_Roaster", "Group_ServiceAdmin", "Group_ServiceManager", "Group_ServiceSales", "Group_TSCUser", "Group_WorkshopRepairCoordinator" ], "IsActive" : true, "SequenceNo" : 0, "Type" : "EventMessageAction" } ], "IsActive" : true, "TargetUsers" : null, "TargetGroups" : null, "Type" : "Rule"}文件2:{ "_id" : ObjectId("5b0bc01fcd8d2966e0fdf2f2"), "Expression" : "HasProperty('category') && [category] = 'Temperature'", "Name" : "RTF Machine Temperature (History Data)", "Actions" : [ { "Table" : "[machinename]", "Key" : "'RTF'", "Value" : "[value]", "Timestamp" : "[timestamp]", "ExpirationDate" : "[timestamp]", "Icon" : "''", "Color" : "''", "Text" : "''", "Category" : "[category]", "IsActive" : true, "Type" : "HistoryDataAction", "SequenceNo" : 0 } ], "IsActive" : true, "TargetUsers" : null, "TargetGroups" : null, "Type" : "Rule"}有什么办法,我可以通过我的实体获取上述记录,如下所示:规则实体:[DataContract]public abstract class Rule { [DataMember] public string Expression { get; set; } [DataMember] public string Name { get; set; } [DataMember] public IEnumerable<Action> Actions { get; set; } [DataMember] public bool IsActive { get; set; } }
1 回答
慕勒3428872
TA贡献1848条经验 获得超6个赞
使用 BsonKnownTypes 属性装饰您的基本类型(Action)。例如:
[BsonKnownTypes(typeof(EventMessageAction),
typeof(HistoryDataAction))]
public class Action
{
}
[更新] 您的数据不包含驱动程序需要知道将数据映射到什么类型的类型键。如果可能,将“Type”键重命名或复制为“_t”
- 1 回答
- 0 关注
- 175 浏览
添加回答
举报
0/150
提交
取消