-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathEntityClass.scriban-cs
More file actions
210 lines (201 loc) · 8.99 KB
/
EntityClass.scriban-cs
File metadata and controls
210 lines (201 loc) · 8.99 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/// <summary>
{{~ for line in table.Description | string.split '\n' ~}}
/// <para>{{ line | string.strip }}</para>
{{~ end ~}}
/// <para>Display Name: {{ table.DisplayName }}</para>
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("DataverseProxyGenerator", "{{version}}")]
[EntityLogicalName("{{table.LogicalName}}")]
[DebuggerDisplay("{DebuggerDisplay,nq}")]
[DataContract]
#pragma warning disable CS8981 // Allows: Only lowercase characters
public partial class {{table.SchemaName}} : ExtendedEntity{{ if table.InterfacesList.size > 0 }}, {{ table.InterfacesList | array.join ", " }}{{ end }}
#pragma warning restore CS8981
{
public const string EntityLogicalName = "{{table.LogicalName}}";
public const int EntityTypeCode = {{table.EntityTypeCode}};
public {{table.SchemaName}}() : base(EntityLogicalName) { }
public {{table.SchemaName}}(Guid id) : base(EntityLogicalName, id) { }
private string DebuggerDisplay => GetDebuggerDisplay("{{ table.PrimaryNameAttribute }}");
[AttributeLogicalName("{{ table.PrimaryIdAttribute }}")]
public override Guid Id {
get {
return base.Id;
}
set {
SetId("{{ table.PrimaryIdAttribute }}", value);
}
}
{{~ for column in table.Columns | array.sort "LogicalName" ~}}
{{~ if column.Description || column.DisplayName ~}}
/// <summary>
{{~ if column.Description && column.Description != "" && column.Description != " " && column.Description != " " && column.Description != " " && column.Description != "\t" && column.Description != "\n" && column.Description != "\r\n" ~}}
{{~ for line in column.Description | string.split '\n' ~}}
/// <para>{{ line | string.strip }}</para>
{{~ end ~}}
{{~ end ~}}
{{~ if column.DisplayName ~}}
/// <para>Display Name: {{ column.DisplayName }}</para>
{{~ end ~}}
/// </summary>
{{~ end ~}}
[AttributeLogicalName("{{ column.LogicalName }}")]
[DisplayName("{{ column.DisplayName }}")]
{{~ if column.IsObsolete ~}}
[ObsoleteAttribute()]
{{~ end ~}}
{{~ if column.TypeName == "StringColumnModel" || column.TypeName == "MemoColumnModel" ~}}
[MaxLength({{ column.MaxLength }})]
public string {{column.SchemaName}}
{
get => GetAttributeValue<string>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "IntegerColumnModel" ~}}
[Range({{ column.Min }}, {{ column.Max }})]
public int? {{column.SchemaName}}
{
get => GetAttributeValue<int?>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "BigIntColumnModel" ~}}
public long? {{column.SchemaName}}
{
get => GetAttributeValue<long?>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "BooleanColumnModel" ~}}
public bool? {{column.SchemaName}}
{
get => GetAttributeValue<bool?>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "DateTimeColumnModel" ~}}
public DateTime? {{column.SchemaName}}
{
get => GetAttributeValue<DateTime?>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "DecimalColumnModel" ~}}
public decimal? {{column.SchemaName}}
{
get => GetAttributeValue<decimal?>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "DoubleColumnModel" ~}}
public double? {{column.SchemaName}}
{
get => GetAttributeValue<double?>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "MoneyColumnModel" ~}}
public decimal? {{column.SchemaName}}
{
get => this.GetMoneyValue("{{column.LogicalName}}");
set => this.SetMoneyValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "EnumColumnModel" ~}}
{{~ if column.IsMultiSelect ~}}
public IEnumerable<{{ column.OptionsetName }}> {{column.SchemaName}}
{
get => this.GetOptionSetCollectionValue<{{ column.OptionsetName }}>("{{column.LogicalName}}");
set => this.SetOptionSetCollectionValue("{{column.LogicalName}}", value);
}
{{~ else ~}}
public {{ column.OptionsetName }}? {{column.SchemaName}}
{
get => this.GetOptionSetValue<{{ column.OptionsetName }}>("{{column.LogicalName}}");
set => this.SetOptionSetValue("{{column.LogicalName}}", value);
}
{{~ end ~}}
{{~ else if column.TypeName == "LookupColumnModel" ~}}
public EntityReference? {{column.SchemaName}}
{
get => GetAttributeValue<EntityReference?>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "PartyListColumnModel" ~}}
public IEnumerable<ActivityParty> {{column.SchemaName}}
{
get => GetEntityCollection<ActivityParty>("{{column.LogicalName}}");
set => SetEntityCollection("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "FileColumnModel" || column.TypeName == "ImageColumnModel" ~}}
public byte[] {{column.SchemaName}}
{
get => GetAttributeValue<byte[]>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "UniqueIdentifierColumnModel" ~}}
public Guid? {{column.SchemaName}}
{
get => GetAttributeValue<Guid?>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "BooleanManagedColumnModel" ~}}
public BooleanManagedProperty {{column.SchemaName}}
{
get => GetAttributeValue<BooleanManagedProperty>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "ManagedColumnModel" ~}}
public ManagedProperty<{{column.FullReturnType}}> {{column.SchemaName}}
{
get => GetAttributeValue<ManagedProperty<{{column.FullReturnType}}>>("{{column.LogicalName}}");
set => SetAttributeValue("{{column.LogicalName}}", value);
}
{{~ else if column.TypeName == "PrimaryIdColumnModel" ~}}
public Guid {{column.SchemaName}}
{
get => GetAttributeValue<Guid>("{{column.LogicalName}}");
set => SetId("{{column.LogicalName}}", value);
}
{{~ end ~}}
{{~ if !for.last ~}}
{{~ end ~}}
{{~ end ~}}
{{~ if ! table.IsIntersect ~}}
{{~ for rel in table.Relationships ~}}
{{~ if rel.RelationshipType == "ManyToOne" ~}}
[AttributeLogicalName("{{ rel.ThisEntityAttribute }}")]
{{~ end ~}}
[RelationshipSchemaName("{{ rel.SchemaName }}")]
[RelationshipMetadata("{{ rel.RelationshipType }}", "{{ rel.ThisEntityAttribute }}", "{{ rel.RelatedEntity }}", "{{ rel.RelatedEntityAttribute }}", "{{ rel.ThisEntityRole }}")]
public {{ if rel.RelationshipType == "OneToMany" || rel.RelationshipType == "ManyToMany" }}IEnumerable<{{ rel.RelatedEntitySchemaName }}> {{ rel.SchemaName }}
{
get => GetRelatedEntities<{{ rel.RelatedEntitySchemaName }}>("{{ rel.SchemaName }}", null);
set => SetRelatedEntities("{{ rel.SchemaName }}", null, value);
}
{{~ else if rel.RelationshipType == "ManyToOne" }}{{ rel.RelatedEntitySchemaName }} {{ rel.SchemaName }}
{
get => GetRelatedEntity<{{ rel.RelatedEntitySchemaName }}>("{{ rel.SchemaName }}", null);
set => SetRelatedEntity("{{ rel.SchemaName }}", null, value);
}
{{~ end ~}}
{{~ if !for.last ~}}
{{~ end ~}}
{{~ end ~}}
{{~ end ~}}
/// <summary>
/// Gets the logical column name for a property on the {{table.SchemaName}} entity, using the AttributeLogicalNameAttribute if present.
/// </summary>
/// <param name="column">Expression to pick the column</param>
/// <returns>Name of column</returns>
/// <exception cref="ArgumentNullException">If no expression is provided</exception>
/// <exception cref="ArgumentException">If the expression is not x => x.column</exception>
public static string GetColumnName(Expression<Func<{{table.SchemaName}}, object>> column)
{
return TableAttributeHelpers.GetColumnName(column);
}
/// <summary>
/// Retrieves the {{table.SchemaName}} with the specified columns.
/// </summary>
/// <param name="service">Organization service</param>
/// <param name="id">Id of {{table.SchemaName}} to retrieve</param>
/// <param name="columns">Expressions that specify columns to retrieve</param>
/// <returns>The retrieved {{table.SchemaName}}</returns>
public static {{table.SchemaName}} Retrieve(IOrganizationService service, Guid id, params Expression<Func<{{table.SchemaName}}, object>>[] columns)
{
return service.Retrieve(id, columns);
}
}