-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathEntityAttributeData.cs
More file actions
79 lines (70 loc) · 2.3 KB
/
EntityAttributeData.cs
File metadata and controls
79 lines (70 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Text.Json;
using Revo.DataAccess.Entities;
using Revo.Domain.ReadModel;
namespace Revo.Extensions.History.ChangeTracking.Model
{
[TablePrefix(NamespacePrefix = "RHI", ColumnPrefix = "EAD")]
public class EntityAttributeData : EntityReadModel
{
private string attributeValueMapJson;
private Dictionary<string, dynamic> attributeValueMap = [];
public EntityAttributeData(Guid id, Guid? aggregateId, Guid? entityId)
{
Id = id;
AggregateId = aggregateId;
EntityId = entityId;
}
protected EntityAttributeData()
{
}
public Guid? AggregateId { get; private set; }
public Guid? EntityId { get; private set; }
public string AttributeValueMapJson
{
get
{
return attributeValueMapJson ??= JsonSerializer.Serialize(attributeValueMap);
}
private set
{
attributeValueMapJson = value;
if (string.IsNullOrWhiteSpace(attributeValueMapJson))
{
attributeValueMap = [];
}
else
{
attributeValueMap = JsonSerializer.Deserialize<Dictionary<string, dynamic>>(attributeValueMapJson);
}
}
}
public bool TryGetAttributeValue<T>(string attributeName, out T value)
{
if (attributeValueMap.TryGetValue(attributeName, out dynamic token))
{
value = (T)token;
return true;
}
else
{
value = default;
return false;
}
}
public void SetAttributeValue<T>(string attributeName, T attributeValue)
{
attributeValueMap[attributeName] = attributeValue;
attributeValueMapJson = null;
}
/*private IEnumerable<KeyValuePair<string, JToken>> AttributeValues
{
get
{
return attributeValueMap?.Properties().Select(x => new KeyValuePair<string, JToken>(x.Name, x.Value))
?? Enumerable.Empty<KeyValuePair<string, JToken>>();
}
}*/
}
}