I'm trying to use the CSLA.NET framework with my companies existing data provider architecture. The architecture is that we have a data provider component that handles all database interaction and is configurable using a configuration file to switch the database and data provider it will use. The problem I am having is that in the examples, all data access code was written in the Business Objects themselves and I can't do this. What is the best way for me to be able to implement this framework w/o having the SQL in the BO? Below is a code sample:
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using Csla;
5 using Csla.Data;
6
7 namespace TPL
8 {
9 [Serializable]
10 public class TPLAgency : BusinessBase<TPLAgency>
11 {
12 private int _intAgencyID;
13 private string _strAgencyName;
14 private string _strAgencyContact;
15 private string _strAddressLine1;
16 private string _strAddressLine2;
29
30 public TPLAgency()
31 {
32 _intAgencyID = 0;
33 }
34
35 #region Properties
36 /// <summary>
37 /// Gets or sets the agency ID.
38 /// </summary>
39 /// <value>The agency ID.</value>
40 [System.ComponentModel.DataObjectField(true,true)]
41 public int AgencyID
42 {
43 get
44 {
45 CanReadProperty("AgencyID", true);
46 return _intAgencyID;
47 }
48 set
49 {
50 CanWriteProperty("AgencyID", true);
51 _intAgencyID = value;
52 }
53 }
54
55 /// <summary>
56 /// Gets or sets the name of the agency.
57 /// </summary>
58 /// <value>The name of the agency.</value>
59 public string AgencyName
60 {
61 get
62 {
63 CanReadProperty("AgencyName", true);
64 return _strAgencyName;
65 }
66 set
67 {
68 CanWriteProperty("AgencyName", true);
69 _strAgencyName = value;
70 }
71 }
72
73 /// <summary>
74 /// Gets or sets the agency contact.
75 /// </summary>
76 /// <value>The agency contact.</value>
77 public string AgencyContact
78 {
79 get
80 {
81 CanReadProperty("AgencyContact", true);
82 return _strAgencyContact;
83 }
84 set
85 {
86 CanWriteProperty("AgencyContact", true);
87 _strAgencyContact = value;
88 }
89 }
90
91 /// <summary>
92 /// Gets or sets the address line1.
93 /// </summary>
94 /// <value>The address line1.</value>
95 public string AddressLine1
96 {
97 get
98 {
99 CanReadProperty("AddressLine1", true);
100 return _strAddressLine1;
101 }
102 set
103 {
104 CanWriteProperty("AddressLine1", true);
105 _strAddressLine1 = value;
106 }
107 }
108
109 /// <summary>
110 /// Gets or sets the address line2.
111 /// </summary>
112 /// <value>The address line2.</value>
113 public string AddressLine2
114 {
115 get
116 {
117 CanReadProperty("AddressLine2", true);
118 return _strAddressLine2;
119 }
120 set
121 {
122 CanWriteProperty("AddressLine2", true);
123 _strAddressLine2 = value;
124 }
125 }
324
325 protected override object GetIdValue()
326 {
327 return _intAgencyID;
328 }
329
330 #endregion
370 #region Factory Methods
371
372 public static TPLAgency NewAgency()
373 {
374 return DataPortal.Create<TPLAgency>();
375 }
376
377 public static TPLAgency GetAgency(int id)
378 {
379 return DataPortal.Fetch<TPLAgency>(new Criteria(id));
380 }
381
382 public static void DeleteAgency(int id)
383 {
384 DataPortal.Delete(new Criteria(id));
385 }
386
387 #endregion
388 #region Data Access
389
390 [Serializable()]
391 private class Criteria
392 {
393 private int mId;
394 public int Id
395 {
396 get
397 { return mId; }
398 }
399 public Criteria(int id)
400 { mId = id; }
401 }
402
403 [RunLocal()]
404 protected override void DataPortal_Create()
405 {
406 AgencyID = 0;
407 }
408
409 private void DataPortal_Fetch(Criteria criteria)
410 {
411 TPLAgency a = CoreGlobal.DBInterface.GetAgency(criteria.Id);
412 _intAgencyID = a.AgencyID;
413 _strAgencyName = a.AgencyName;
414 _strAgencyContact = a.AgencyContact;
415 _strAddressLine1 = a.AddressLine1;
416 _strAddressLine2 = a.AddressLine2;
417 _strAddressLine3 = a.AddressLine3;
418 _strAddressLine4 = a.AddressLine4;
419 _strAddressLine5 = a.AddressLine5;
420 _strTown = a.Town;
421 _strProvince = a.Province;
422 _strRegion = a.Region;
423 _strTelephone = a.Telephone;
424 _strFax = a.Fax;
425 _strEmail = a.Email;
426 _objCountry = a.Country;
427 }
428
429 protected override void DataPortal_Insert()
430 {
431 // TODO: insert object's data
432 }
433
434 protected override void DataPortal_Update()
435 {
436 // TODO: update object's data
437 }
438
439 protected override void DataPortal_DeleteSelf()
440 {
441 DataPortal_Delete(new Criteria(_intAgencyID));
442 }
443
444 private void DataPortal_Delete(Criteria criteria)
445 {
446 // TODO: delete object's data
447 }
448
449 #endregion
450
451 }
452 }
nermin:I believe you are looking for "Deep Data" example (a solution). It is somewhere on lhotka.net - I downloaded it couple of months ago but I am having hard time finding it now.
I do have a search page on my site
http://www.lhotka.net/Search.aspx
Click here to get to the download page you are looking for.
Copyright (c) Marimer LLC