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.
StronglyTypedDP.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="StronglyTypedDP.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;
11
13{
14 [Serializable()]
15 public class StronglyTypedDP : BusinessBase<StronglyTypedDP>
16 {
17 public static PropertyInfo<int> IdProperty = RegisterProperty<int>(c => c.Id);
18 public int Id
19 {
20 get { return GetProperty(IdProperty); }
21 set { SetProperty(IdProperty, value); }
22 }
23
24 public static PropertyInfo<string> DataProperty = RegisterProperty<string>(c => c.Data);
25 public string Data
26 {
27 get { return GetProperty(DataProperty); }
28 set { SetProperty(DataProperty, value); }
29 }
30
31 //criteria class needs to be protected since DataPortal_xyz methods are
32 //protected
33 [Serializable()]
34 protected class Criteria
35 {
36 public string _data;
37 public int _ID;
38
39 public Criteria()
40 {
41 _data = "new default data";
42 _ID = 56;
43 }
44
45 public Criteria(int id)
46 {
47 this._ID = id;
48 this._data = "fetched existing data";
49 }
50 }
51
53 {
54 return dataPortal.Create(new StronglyTypedDP.Criteria());
55 }
56
58 {
59 return dataPortal.Fetch(new StronglyTypedDP.Criteria(id));
60 }
61
62 public static void DeleteStronglyTypedDP(int id, IDataPortal<StronglyTypedDP> dataPortal)
63 {
64 dataPortal.Delete(new Criteria(id));
65 }
66
68 {
69 using (BypassPropertyChecks)
70 {
71 Data = criteria._data;
72 Id = criteria._ID;
73 }
74 TestResults.Add("StronglyTypedDP", "Created");
75 }
76
77 protected void DataPortal_Fetch(StronglyTypedDP.Criteria criteria)
78 {
79 using (BypassPropertyChecks)
80 {
81 Data = criteria._data;
82 Id = criteria._ID;
83 }
84 MarkOld();
85 TestResults.Add("StronglyTypedDP", "Fetched");
86 }
87
88 [Insert]
89 protected void DataPortal_Insert()
90 {
91 TestResults.Add("StronglyTypedDP", "Inserted");
92 }
93
94 [Update]
95 protected void DataPortal_Update()
96 {
97 TestResults.Add("StronglyTypedDP", "Updated");
98 }
99
100 [DeleteSelf]
101 protected void DataPortal_DeleteSelf()
102 {
103 TestResults.Add("StronglyTypedDP", "Deleted self");
104 }
105
106 [Delete]
108 {
109 TestResults.Add("StronglyTypedDP_Criteria", criteria._ID.ToString());
110 }
111 }
112}
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
Maintains metadata about a property.
static PropertyInfo< int > IdProperty
static StronglyTypedDP NewStronglyTypedDP(IDataPortal< StronglyTypedDP > dataPortal)
void DataPortal_Create(StronglyTypedDP.Criteria criteria)
static void DeleteStronglyTypedDP(int id, IDataPortal< StronglyTypedDP > dataPortal)
static StronglyTypedDP GetStronglyTypedDP(int id, IDataPortal< StronglyTypedDP > dataPortal)
void DataPortal_Delete(StronglyTypedDP.Criteria criteria)
static PropertyInfo< string > DataProperty
void DataPortal_Fetch(StronglyTypedDP.Criteria criteria)
Static dictionary-like class that offers similar functionality to GlobalContext This is used in tests...
Definition: TestResults.cs:21
static void Add(string key, string value)
Add an item to the test results, to indicate an outcome of a particular operation
Definition: TestResults.cs:29
Interface defining the members of the data portal type.
Definition: IDataPortalT.cs:17
void Delete(params object[] criteria)
Called by a Shared (static in C#) method in the business class to cause immediate deletion of a speci...
object Fetch(params object[] criteria)
Called by a factory method in a business class to retrieve an object, which is loaded with values fro...
object Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Update
Update operation (includes insert, update and delete self).
@ Delete
Delete operation.