CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Csla.test/Basic/Child.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="Child.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Text;
11using System.Data;
12
13namespace Csla.Test.Basic
14{
15 [Serializable()]
16 public class Child : BusinessBase<Child>
17 {
18 public static PropertyInfo<string> DataProperty = RegisterProperty<string>(nameof(Data));
19 public static PropertyInfo<Guid> GuidProperty = RegisterProperty<Guid>(nameof(Guid));
20 public static PropertyInfo<GrandChildren> GrandChildrenProperty = RegisterProperty<GrandChildren>(c => c.GrandChildren);
21
22 protected override object GetIdValue()
23 {
24 return ReadProperty(DataProperty);
25 }
26
27 public string Data
28 {
29 get { return GetProperty(DataProperty); }
30 set { SetProperty(DataProperty, value); }
31 }
32
33 public override bool Equals(object obj)
34 {
35 if (obj == null || !(obj is Child))
36 {
37 return false;
38 }
39
40 return ReadProperty(DataProperty) == ((Child)(obj)).ReadProperty(DataProperty);
41 }
42
43 public override int GetHashCode()
44 {
45 return base.GetHashCode();
46 }
47
48 public Guid Guid
49 {
50 get { return ReadProperty(GuidProperty); }
51 }
52
54 {
55 get { return GetProperty(GrandChildrenProperty); }
56 }
57
58 internal static Child NewChild(IDataPortal<Child> dataPortal, string data)
59 {
60 return dataPortal.Create(data);
61 }
62
63 internal static Child GetChild(IDataPortal<Child> dataPortal, IDataReader dr)
64 {
65 Child obj;
66 obj = dataPortal.Fetch(dr);
67 return obj;
68 }
69
70 public Child()
71 {
72 MarkAsChild();
73 }
74
75 [Create]
76 [CreateChild]
77 private void Create(string data, [Inject] IChildDataPortal<GrandChildren> childDataPortal)
78 {
79 LoadProperty(GuidProperty, Guid.NewGuid());
80 LoadProperty(DataProperty, data);
81 LoadProperty(GrandChildrenProperty, childDataPortal.CreateChild());
82 }
83
84 [Fetch]
85 [FetchChild]
86 private void Fetch(IDataReader dr, [Inject] IChildDataPortal<GrandChildren> childDataPortal)
87 {
88 LoadProperty(GrandChildrenProperty, childDataPortal.CreateChild());
89 }
90
91 [UpdateChild]
92 internal void Update(IDbTransaction tr)
93 {
94 if (IsDeleted)
95 {
96 //we would delete here
97 MarkNew();
98 }
99 else
100 {
101 if (IsNew)
102 {
103 //we would insert here
104 }
105 else
106 {
107 //we would update here
108 }
109 MarkOld();
110 }
111 }
112 }
113}
Maintains metadata about a property.
override bool Equals(object obj)
override object GetIdValue()
Override this method to return a unique identifying value for this object.
static readonly PropertyInfo< GrandChildren > GrandChildrenProperty
static readonly PropertyInfo< string > DataProperty
static PropertyInfo< Guid > GuidProperty
Interface defining the members of the child data portal type.
@ Serializable
Prevents updating or inserting until the transaction is complete.