needs to be like this - this is correct and working:
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated using CodeSmith: v5.2.1, CSLA Templates:
v2.0.1.1576, CSLA Framework: v3.8.2.
// Changes to this file will be lost after each regeneration.
// To extend the functionality of this class, please modify the partial
class 'Member.cs'.
//
// Template: EditableChild.DataAccess.StoredProcedures.cst
// Template website: http://code.google.com/p/codesmith/
// </autogenerated>
//------------------------------------------------------------------------------
#region Using declarations
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
#endregion
namespace RecoveryPlanner.Business
{
public partial class Member
{
protected override void Child_Create()
{
bool cancel = false;
OnChildCreating(ref cancel);
if (cancel) return;
ValidationRules.CheckRules();
OnChildCreated();
}
private void Child_Fetch(MemberCriteria criteria)
{
bool cancel = false;
OnChildFetching(criteria, ref cancel);
if (cancel) return;
using (SqlConnection connection = new
SqlConnection(ADOHelper.ConnectionString))
{
connection.Open();
using (SqlCommand command = new
SqlCommand("[dbo].[rp_Member_Select]", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
command.Parameters.AddWithValue("@clientNameHasValue",
criteria.ClientNameHasValue);
command.Parameters.AddWithValue("@BranchIDHasValue",
criteria.BranchIDHasValue);
command.Parameters.AddWithValue("@StatusIDHasValue",
criteria.StatusIDHasValue);
command.Parameters.AddWithValue("@MainHasValue", criteria.MainHasValue);
command.Parameters.AddWithValue("@Entered_TimestampHasValue",
criteria.EnteredTimestampHasValue);
command.Parameters.AddWithValue("@Inactive_TimestampHasValue",
criteria.InactiveTimestampHasValue);
using(var reader = new
SafeDataReader(command.ExecuteReader()))
{
if(reader.Read())
Map(reader);
else
throw new Exception(string.Format("The record
was not found in 'Member' using the following criteria: {0}.", criteria));
}
}
}
OnChildFetched();
}
/*private void Child_Insert(SqlConnection connection) //this one is
never used, always called WITH the parent object + connection. Never just
with a connection
{
bool cancel = false;
OnChildInserting(connection, ref cancel);
if (cancel) return;
if(connection.State != ConnectionState.Open) connection.Open();
using(SqlCommand command = new
SqlCommand("[dbo].[rp_Member_Insert]", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@ProjectID", this.ProjectID);
command.Parameters.AddWithValue("@memberID", this.MemberID);
command.Parameters["@memberID"].Direction = ParameterDirection.Output;
command.Parameters.AddWithValue("@clientName",
ADOHelper.NullCheck(this.ClientName));
command.Parameters.AddWithValue("@BranchID",
ADOHelper.NullCheck(this.BranchID));
command.Parameters.AddWithValue("@StatusID",
ADOHelper.NullCheck(this.StatusID));
command.Parameters.AddWithValue("@Main", ADOHelper.NullCheck(this.Main));
command.Parameters.AddWithValue("@Entered_Timestamp",
ADOHelper.NullCheck(this.EnteredTimestamp));
command.Parameters.AddWithValue("@Inactive_Timestamp",
ADOHelper.NullCheck(this.InactiveTimestamp));
command.ExecuteNonQuery();
LoadProperty(_originalProjectIDProperty, this.ProjectID);
LoadProperty(_memberIDProperty,(System.Int32)command.Parameters["@memberID"].Val
ue);
}
FieldManager.UpdateChildren(this, connection);
OnChildInserted();
}*/
private void Child_Insert(Project project, SqlConnection connection)
{
bool cancel = false;
OnChildInserting(connection, ref cancel);
if (cancel) return;
if(connection.State != ConnectionState.Open) connection.Open();
using(SqlCommand command = new
SqlCommand("[dbo].[rp_Member_Insert]", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@ProjectID", project !=
null ? project.ProjectID : new System.Int32());
command.Parameters.AddWithValue("@memberID", this.MemberID);
command.Parameters["@memberID"].Direction = ParameterDirection.Output;
command.Parameters.AddWithValue("@clientName",
ADOHelper.NullCheck(this.ClientName));
command.Parameters.AddWithValue("@BranchID",
ADOHelper.NullCheck(this.BranchID));
command.Parameters.AddWithValue("@StatusID",
ADOHelper.NullCheck(this.StatusID));
command.Parameters.AddWithValue("@Main", ADOHelper.NullCheck(this.Main));
command.Parameters.AddWithValue("@Entered_Timestamp",
ADOHelper.NullCheck(this.EnteredTimestamp));
command.Parameters.AddWithValue("@Inactive_Timestamp",
ADOHelper.NullCheck(this.InactiveTimestamp));
command.ExecuteNonQuery();
LoadProperty(_originalProjectIDProperty, this.ProjectID);
LoadProperty(_memberIDProperty,(System.Int32)command.Parameters["@memberID"].Val
ue);
}
//<--- this class doesn't have any children! So remove this please:
//FieldManager.UpdateChildren(this, connection); //<--- this
class doesn't have any children! So remove this please
OnChildInserted();
}
/*private void Child_Update(SqlConnection connection) //this one is
never used, always called WITH the parent object + connection. Never just
with a connection
{
bool cancel = false;
OnChildUpdating(connection, ref cancel);
if (cancel) return;
if(connection.State != ConnectionState.Open) connection.Open();
using(SqlCommand command = new
SqlCommand("[dbo].[rp_Member_Update]", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@OriginalProjectID",
this.OriginalProjectID);
command.Parameters.AddWithValue("@ProjectID", this.ProjectID);
command.Parameters.AddWithValue("@memberID", this.MemberID);
command.Parameters.AddWithValue("@clientName",
ADOHelper.NullCheck(this.ClientName));
command.Parameters.AddWithValue("@BranchID",
ADOHelper.NullCheck(this.BranchID));
command.Parameters.AddWithValue("@StatusID",
ADOHelper.NullCheck(this.StatusID));
command.Parameters.AddWithValue("@Main", ADOHelper.NullCheck(this.Main));
command.Parameters.AddWithValue("@Entered_Timestamp",
ADOHelper.NullCheck(this.EnteredTimestamp));
command.Parameters.AddWithValue("@Inactive_Timestamp",
ADOHelper.NullCheck(this.InactiveTimestamp));
//result: The number of rows changed, inserted, or deleted.
-1 for select statements; 0 if no rows were affected, or the statement failed.
int result = command.ExecuteNonQuery();
if (result == 0)
throw new DBConcurrencyException("The entity is out of
date on the client. Please update the entity and try again. This could also
be thrown if the sql statement failed to execute.");
LoadProperty(_memberIDProperty,(System.Int32)command.Parameters["@memberID"].Val
ue);
LoadProperty(_originalProjectIDProperty, this.ProjectID);
}
FieldManager.UpdateChildren(this, connection);
OnChildUpdated();
}*/
private void Child_Update(Project project, SqlConnection connection)
{
bool cancel = false;
OnChildUpdating(connection, ref cancel);
if (cancel) return;
if(connection.State != ConnectionState.Open) connection.Open();
using(SqlCommand command = new
SqlCommand("[dbo].[rp_Member_Update]", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@OriginalProjectID",
project != null ? OriginalProjectID : new System.Int32());
command.Parameters.AddWithValue("@ProjectID", project != null ?
project.ProjectID : new System.Int32());
command.Parameters.AddWithValue("@memberID", this.MemberID);
command.Parameters.AddWithValue("@clientName",
ADOHelper.NullCheck(this.ClientName));
command.Parameters.AddWithValue("@BranchID",
ADOHelper.NullCheck(this.BranchID));
command.Parameters.AddWithValue("@StatusID",
ADOHelper.NullCheck(this.StatusID));
command.Parameters.AddWithValue("@Main", ADOHelper.NullCheck(this.Main));
command.Parameters.AddWithValue("@Entered_Timestamp",
ADOHelper.NullCheck(this.EnteredTimestamp));
command.Parameters.AddWithValue("@Inactive_Timestamp",
ADOHelper.NullCheck(this.InactiveTimestamp));
//result: The number of rows changed, inserted, or deleted.
-1 for select statements; 0 if no rows were affected, or the statement failed.
int result = command.ExecuteNonQuery();
if (result == 0)
throw new DBConcurrencyException("The entity is out of
date on the client. Please update the entity and try again. This could also
be thrown if the sql statement failed to execute.");
LoadProperty(_memberIDProperty,(System.Int32)command.Parameters["@memberID"].Val
ue);
LoadProperty(_originalProjectIDProperty, this.ProjectID);
}
//<--- this class doesn't have any children! So remove this please
//FieldManager.UpdateChildren(this, connection); //<--- this
class doesn't have any children! So remove this please
OnChildUpdated();
}
private void Child_DeleteSelf(SqlConnection connection)
{
bool cancel = false;
OnChildSelfDeleting(connection, ref cancel);
if (cancel) return;
DataPortal_Delete(new MemberCriteria (ProjectID, MemberID),
connection);
OnChildSelfDeleted();
}
protected void DataPortal_Delete(MemberCriteria criteria,
SqlConnection connection)
{
bool cancel = false;
OnDeleting(criteria, connection, ref cancel);
if (cancel) return;
using (SqlCommand command = new
SqlCommand("[dbo].[rp_Member_Delete]", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
//result: The number of rows changed, inserted, or deleted.
-1 for select statements; 0 if no rows were affected, or the statement failed.
int result = command.ExecuteNonQuery();
if (result == 0)
throw new DBConcurrencyException("The entity is out of
date on the client. Please update the entity and try again. This could also
be thrown if the sql statement failed to execute.");
}
OnDeleted();
}
private void Map(SafeDataReader reader)
{
bool cancel = false;
OnMapping(reader, ref cancel);
if (cancel) return;
using(BypassPropertyChecks)
{
LoadProperty(_projectIDProperty, reader["ProjectID"]);
LoadProperty(_originalProjectIDProperty, reader["ProjectID"]);
LoadProperty(_memberIDProperty, reader["memberID"]);
LoadProperty(_clientNameProperty, reader["clientName"]);
LoadProperty(_branchIDProperty, reader["BranchID"]);
LoadProperty(_statusIDProperty, reader["StatusID"]);
LoadProperty(_mainProperty, reader["Main"]);
LoadProperty(_enteredTimestampProperty,
reader["Entered_Timestamp"]);
LoadProperty(_inactiveTimestampProperty,
reader["Inactive_Timestamp"]);
}
OnMapped();
MarkAsChild();
MarkOld();
}
#region Child data access partial methods
partial void OnChildCreating(ref bool cancel);
partial void OnChildCreated();
partial void OnChildFetching(MemberCriteria criteria, ref bool cancel);
partial void OnChildFetched();
partial void OnMapping(SafeDataReader reader, ref bool cancel);
partial void OnMapped();
partial void OnChildInserting(SqlConnection connection, ref bool
cancel);
partial void OnChildInserted();
partial void OnChildUpdating(SqlConnection connection, ref bool
cancel);
partial void OnChildUpdated();
partial void OnChildSelfDeleting(SqlConnection connection, ref bool
cancel);
partial void OnChildSelfDeleted();
partial void OnDeleting(MemberCriteria criteria, ref bool cancel);
partial void OnDeleting(MemberCriteria criteria, SqlConnection
connection, ref bool cancel);
partial void OnDeleted();
#endregion
}
}
Original issue reported on code.google.com by eirikur....@arionbanki.is on 19 Apr 2010 at 12:14
Original issue reported on code.google.com by
eirikur....@arionbanki.is
on 19 Apr 2010 at 12:14