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.
ESTransactionalRoot.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ESTransactionalRoot.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;
12using System.Data.SqlClient;
13using System.Configuration;
14
16{
17 [Serializable()]
18 public class ESTransactionalRoot : BusinessBase<ESTransactionalRoot>
19 {
20 #region "Business methods"
21
22 //get the configurationmanager to work right
24
25 public static PropertyInfo<int> IDProperty = RegisterProperty<int>(c => c.ID);
26 public int ID
27 {
28 get { return GetProperty(IDProperty); }
29 private set { LoadProperty(IDProperty, value); }
30 }
31
32 public static PropertyInfo<string> FirstNameProperty = RegisterProperty<string>(c => c.FirstName);
33 public string FirstName
34 {
35 get { return GetProperty(FirstNameProperty); }
36 set { SetProperty(FirstNameProperty, value); }
37 }
38
39 public static PropertyInfo<string> LastNameProperty = RegisterProperty<string>(c => c.LastName);
40 public string LastName
41 {
42 get { return GetProperty(LastNameProperty); }
43 set { SetProperty(LastNameProperty, value); }
44 }
45
46 public static PropertyInfo<string> SmallColumnProperty = RegisterProperty<string>(c => c.SmallColumn);
47 public string SmallColumn
48 {
49 get { return GetProperty(SmallColumnProperty); }
50 set { SetProperty(SmallColumnProperty, value); }
51 }
52
53 #endregion
54
55 protected override void AddBusinessRules()
56 {
57 //normally, we would add a rule that prevents SmallColumn from being too long
58 //but to easily test the transactional functionality of the server-side dataportal
59 //we are going to allow strings that are longer than what the database allows
60 }
61
62 #region "Factory Methods"
63
65 {
67 }
68
70 {
71 return Csla.DataPortal.Fetch<ESTransactionalRoot>(new Criteria(ID));
72 }
73
74 public static void DeleteESTransactionalRoot(int ID)
75 {
77 }
78
79 #endregion
80
81 #region "Criteria"
82
83 [Serializable()]
84 private class Criteria
85 {
86 public int _id;
87
88 public Criteria(int id)
89 {
90 this._id = id;
91 }
92 }
93
94 #endregion
95
96 #region "Data Access"
97
98 [RunLocal()]
99 [Create]
100 protected void DataPortal_Create()
101 {
102 Csla.ApplicationContext.GlobalContext.Clear();
103 Csla.ApplicationContext.GlobalContext.Add("ESTransactionalRoot", "Created");
104 BusinessRules.CheckRules();
105 Console.WriteLine("DataPortal_Create");
106 }
107
108 protected void DataPortal_Fetch(object criteria)
109 {
110 Console.WriteLine("DataPortal_Fetch");
111 Csla.ApplicationContext.GlobalContext.Clear();
112 Csla.ApplicationContext.GlobalContext.Add("ESTransactionalRoot", "Fetched");
113 BusinessRules.CheckRules();
114 }
115
116 [Transactional(TransactionalTypes.EnterpriseServices)]
117 [Insert]
118 protected void DataPortal_Insert()
119 {
120 SqlConnection cn = new SqlConnection(CONNECTION_STRING);
121 string firstName = this.FirstName;
122 string lastName = this.LastName;
123 string smallColumn = this.SmallColumn;
124
125 //this command will always execute successfully
126 //since it inserts a string less than 5 characters
127 //into SmallColumn
128 SqlCommand cm1 = new SqlCommand();
129 cm1.Connection = cn;
130 cm1.CommandText = "INSERT INTO Table2(FirstName, LastName, SmallColumn) VALUES('Bill', 'Thompson', 'abc')";
131
132 //this command will throw an exception
133 //if SmallColumn is set to a string longer than
134 //5 characters
135 SqlCommand cm2 = new SqlCommand();
136 cm2.Connection = cn;
137 //use stringbuilder
138 cm2.CommandText = "INSERT INTO Table2(FirstName, LastName, SmallColumn) VALUES('";
139 cm2.CommandText += firstName;
140 cm2.CommandText += "', '" + lastName + "', '" + smallColumn + "')";
141
142 cn.Open();
143 cm1.ExecuteNonQuery();
144 cm2.ExecuteNonQuery();
145 cn.Close();
146
147 Csla.ApplicationContext.GlobalContext.Clear();
148 Csla.ApplicationContext.GlobalContext.Add("ESTransactionalRoot", "Inserted");
149 Console.WriteLine("DataPortal_Insert");
150 }
151
152 [Transactional(TransactionalTypes.EnterpriseServices)]
153 [Update]
154 protected void DataPortal_Update()
155 {
156 Console.WriteLine("DataPortal_Update");
157 Csla.ApplicationContext.GlobalContext.Clear();
158 Csla.ApplicationContext.GlobalContext.Add("ESTransactionalRoot", "Updated");
159 }
160
161 [DeleteSelf]
162 protected void DataPortal_DeleteSelf()
163 {
164 Console.WriteLine("DataPortal_DeleteSelf");
165 Csla.ApplicationContext.GlobalContext.Clear();
166 Csla.ApplicationContext.GlobalContext.Add("ESTransactionalRoot", "Deleted Self");
167 }
168
169 [Delete]
170 protected void DataPortal_Delete(object criteria)
171 {
172 Console.WriteLine("DataPortal_Delete");
173 Csla.ApplicationContext.GlobalContext.Clear();
174 Csla.ApplicationContext.GlobalContext.Add("ESTransactionRoot", "Deleted");
175 }
176
177 #endregion
178 }
179}
Provides consistent context information between the client and server DataPortal objects.
void Clear()
Clears all context collections.
This is the base class from which most business objects will be derived.
Definition: BusinessBase.cs:38
Client side data portal used for making asynchronous data portal calls in .NET.
Definition: DataPortalT.cs:24
void Delete(params object[] criteria)
Called by a factory method in a business class or by the UI to delete an object.
Definition: DataPortalT.cs:545
T Create(params object[] criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
Definition: DataPortalT.cs:151
T Fetch(params object[] criteria)
Called by a factory method in a business class to Fetch a new object, which is loaded with default va...
Definition: DataPortalT.cs:247
Maintains metadata about a property.
static ESTransactionalRoot GetESTransactionalRoot(int ID)
static PropertyInfo< string > LastNameProperty
static PropertyInfo< string > FirstNameProperty
static ESTransactionalRoot NewESTransactionalRoot()
static PropertyInfo< string > SmallColumnProperty
static string DataPortalTestDatabase
TransactionalTypes
Provides a list of possible transactional technologies to be used by the server-side DataPortal.
@ Serializable
Prevents updating or inserting until the transaction is complete.
@ Update
Update operation (includes insert, update and delete self).
@ Create
Create operation.
@ Delete
Delete operation.