CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Problems with CodeSmith C# Template

rated by 0 users
This post has 2 Replies | 0 Followers

Not Ranked
Points 100
Rizshe Posted: Wed, Jan 14 2009 4:20 AM
Hi,
I'm working with CSLA2.0 for sometime.
In a recent project we tried to use CodeSmith to generate C# templates and I'm having problems.
Maybe its my understanding OR my lack of knowledge, either way I need some serious help.

This is the actual code which I wrote a while back.

namespace BDD.MyImpact.Library.BO
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using BDD.MyImpact.Library.Data;

///
/// Readonlylist of a Person Publications
///
[Serializable]
public class PersonPublicationList : ReadOnlyList
{
String _user = String.Empty;
public String User
{
get
{
return this._user;
}
}

#region Factory Methods
private PersonPublicationList()
{

}

public static PersonPublicationList GetPublicationList(String user)
{
return DataPortal.Fetch(new Criteria(user));
}
#endregion

#region Criteria
[Serializable()]
private class Criteria
{
private String _user;

public String User
{
get
{
return this._user;
}
}

public Criteria(String login)
{
this._user = login;
}

}

#endregion

#region Data Access

private void DataPortal_Fetch(Criteria criteria)
{
using (SqlConnection cn = new SqlConnection(Database.MyImpactConnection))
{
cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "miapp.pc_get_PersonPublicationList";
cm.Parameters.AddWithValue("@user", criteria.User);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
IsReadOnly = false;
while (dr.Read())
{
PublicationInfo info = new PublicationInfo(dr.GetInt32("pub_id"),
dr.GetString("Title").ToString(),
dr.GetInt16("Year"),
dr.GetString("web_html"),
dr.GetString("journal"));
this.Add(info);

}
IsReadOnly = true;
}
}
}

}
#endregion
}
}
---------------------------------------
I already have a child object for this class which is already in use by another parent class that is why I don't want to generate the child.

---------------------------------------------
I tried to do SplitPartial but disregard it after I find it a bit rigid in terms of modification as I regarded the generated classes not to be touched and user classes are the ones to be modifiable.
I then sort of go towards the SplitBase as I can easily override the methods but here again I'm having problems.
Here is the code the XML template above generated.

using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using BDD.MyImpact.Library.Data;

namespace BDD.MyImpact.Library.BO
{
[Serializable()]
public abstract class PersonPublicationListBase : Csla.ReadOnlyListBase
where T : PersonPublicationListBase
where C : PublicationInfoBase
{

#region Factory Methods
public static T GetPersonPublicationList()
{
return DataPortal.Fetch(new FilterCriteria());
}
#endregion //Factory Methods

#region Data Access

#region Filter Criteria
[Serializable()]
protected class FilterCriteria : Csla.CriteriaBase
{

public FilterCriteria() : base(typeof(T))
{

}
}
#endregion //Filter Criteria

#region Data Access - Fetch
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Fetch(FilterCriteria criteria)
{
RaiseListChangedEvents = false;
IsReadOnly = false;

using (SqlConnection cn = new SqlConnection(Database.MyImpactConnection))
{
cn.Open();

ExecuteFetch(cn, criteria);
}//using

IsReadOnly = true;
RaiseListChangedEvents = true;
}

protected virtual void ExecuteFetch(SqlConnection cn, FilterCriteria criteria)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "pc_get_PersonPublicationList";


using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read())
this.Add(PublicationInfoBase.GetPublicationInfo(dr));
}
}//using
}
#endregion //Data Access - Fetch
#endregion //Data Access
}
}

------------------------------------
Now If you take a look at the code which I wrote and the code which is generated there are differences and I couldn't find a way to sort of get rid of those differences which is essential to let me work?
Any ideas?

Thanks
  • | Post Points: 5
Not Ranked
Points 100
Rizshe replied on Fri, Jan 16 2009 9:53 AM
Isn't there anyone who explain as all I need is an explanation :)

Regards,
Rizwan
  • | Post Points: 20
Top 100 Contributor
Points 875
Hello,

To make the changes in the generated code you would need to open up the CodeSmith Template in CodeSmith Studio or notepad and make the changes and regenerate. For the current CodeSmith CSLA templates, I would log all bugs on the CSLA CodePlex Site.

Just a heads up that we are currently creating new CSLA 3.6.x templates for CodeSmith. If you have any suggestions please let me know.

Thanks
-Blake Niemyjski

Thanks

-Blake Niemyjski (Author of the CodeSmith CSLA templates).

  • | Post Points: 5
Page 1 of 1 (3 items) | RSS

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems