Ugg... So I am getting this error message when trying to create an instance of my child class by calling:
UserAccount tmpAccount = UserAccount.GetUserAccountByUserID(tmpUser.UserID);
Any ideas what I have wrong in my child class?
THANKS!!!!!
[
Serializable()] public class UserAccount : Csla.BusinessBase<UserAccount>{
private string _id; private string _PhoneNumber; private string _MobileNumber;public string id
{
get{
CanReadProperty(
true); return _id;}
set{
if (_id != value){
_id =
value;PropertyHasChanged(
"id");}
}
}
public string PhoneNumber{
get{
CanReadProperty(
true); return _PhoneNumber;}
set{
_PhoneNumber =
value;PropertyHasChanged(
"PhoneNumber");}
}
public string MobileNumber{
get{
CanReadProperty(
true); return _MobileNumber;}
set{
_MobileNumber =
value;PropertyHasChanged(
"MobileNumber");}
}
#region
Business Methods public string Tester(){
return "tester";}
protected override object GetIdValue()
{
return _id;}
#endregion
#region
Validation Rules protected override void AddBusinessRules(){
// ValidationRules.AddRule<Role>(NoDuplicates, "Id");
// ValidationRules.AddRule(
// Csla.Validation.CommonRules.StringRequired, "Name");
}
// private static bool NoDuplicates<T>(T target, Csla.Validation.RuleArgs e) where T: Role
// {
// Roles parent = (Roles)target.Parent;
// if (parent != null)
// {
// foreach (Role item in parent)
// if (item.Id == target._id && !ReferenceEquals(item, target))
// {
// e.Description = "Role Id must be unique";
// return false;
// }
// }
// return true;
// }
#endregion
#region
Authorization Rules protected override void AddAuthorizationRules(){
// AuthorizationRules.AllowWrite(
// "Id", "Administrator");
// AuthorizationRules.AllowWrite(
// "Name", "Administrator");
}
#endregion
#region
Factory Methodspublic static UserAccount GetUserAccountByUserID(string id)
{
return DataPortal.Fetch<UserAccount>(id);}
internal static UserAccount NewUserAccount(){
return DataPortal.Create<UserAccount>();}
internal static UserAccount GetUserAccount(string id){
return new UserAccount(id);}
private UserAccount(){
MarkAsChild();
//ValidationRules.CheckRules();}
private UserAccount(string id){
MarkAsChild();
Fetch(id);
}
#endregion
#region
Data Access private void Fetch(string id){
_id = id;
General tmpUtils = new General(); DataTools tmpData = new DataTools(); DataSet tmpDataSet = tmpData.ExecuteDataset(String.Format("SELECT UserAccount.* FROM UserAccount INNER JOIN UserTimeStamps ON UserAccount.TimeStamp = UserTimeStamps.TimeStamp WHERE UserTimeStamps.UserGUID ='{0}' and UserTable = '{1}'", _id, "UserAccount")); DataView tmpReturnedData;tmpReturnedData =
new DataView();tmpReturnedData.Table = tmpDataSet.Tables[
"DataReturned"]; foreach (DataRow d in tmpReturnedData.Table.Rows){
switch (d["FieldName"].ToString()){
case "PhoneNumber":PhoneNumber = d[
"FieldValue"].ToString(); break; case "MobileNumber":MobileNumber = d[
"FieldValue"].ToString(); break;}
}
MarkOld();
}
internal void Insert(){
// if we're not dirty then don't update the database if (!this.IsDirty) return;}
internal void Update(){
// if we're not dirty then don't update the database. if (!this.IsDirty) return;}
internal void DeleteSelf()
{
// if we're not dirty then don't update the database if (!this.IsDirty) return; // if we're new then don't update the database if (this.IsNew) return; //DeleteRole(_id);MarkNew();
}
internal static void DeleteUserAccount(int id){
}
#endregion
}
}
A Child object cannot Fetch or do any other CRUD operations on its own volition. The respective Parent must perform these actions. Usually that will be an Editable Root or Collection object.
The other two responders are correct.
You are mixing up child and root concepts.
Since you marked this BO as a child it should be contained in some parent root BO or collection.
A child BO does NOT call DataPortal.Fetch.
e.g. it should look more like this: (note the pased in dr comes from the parent BO.)
Protected
Friend Shared Function GetMyChild(ByVal dr As SafeDataReader) AsMyChild MarkOld()
ValidationRules.CheckRules()
Thanks for everyones help! I think I am almost there. Everything is working except for the save method. When I make changes to the child, but not changes to the parent the parent.save() doesn't detect that the child isdirty.
Copyright (c) Marimer LLC