Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
GeneralRe: Open file error does not produce exception Pin
CTaylor8916-Aug-07 10:10
CTaylor8916-Aug-07 10:10 
GeneralRe: Open file error does not produce exception [modified] Pin
Justin Perez16-Aug-07 10:15
Justin Perez16-Aug-07 10:15 
GeneralRe: Open file error does not produce exception Pin
CTaylor8916-Aug-07 10:36
CTaylor8916-Aug-07 10:36 
GeneralRe: Open file error does not produce exception Pin
Justin Perez23-Aug-07 2:10
Justin Perez23-Aug-07 2:10 
GeneralRe: Open file error does not produce exception Pin
CTaylor8927-Aug-07 6:14
CTaylor8927-Aug-07 6:14 
Question[C#] - Obtaining no: of files & file sizes Pin
aravinda77716-Aug-07 8:40
aravinda77716-Aug-07 8:40 
AnswerRe: [C#] - Obtaining no: of files & file sizes Pin
Luc Pattyn16-Aug-07 8:45
sitebuilderLuc Pattyn16-Aug-07 8:45 
Question[SOLVED] Castle ActiveRecord and abstract classes... Pin
Xiol3216-Aug-07 7:19
Xiol3216-Aug-07 7:19 
Hey folks. Not sure if this belongs here but it seems to me it's more of a C# thing than an SQL thing.

I'm writing a reporting program for the high school I work for, to allow teachers to write reports with pre-defined statements. We already have one in place that's written with Access, but it's a PITA and needs replacing, hence me breaking out the C#.

Now I'm amateurish at best (I'm IT Support, not a programmer for starters), so lets get that out of the way!

I'm using Castle ActiveRecord to let me do ORM and handle my database for me. I have four Achievement tables and 3 Target tables and they all have the same layout (schema?) of (Id, Subject, Comment, YearGroup) - so we have tables in the db called Achieve1 - Achieve4, and Target1 - Target3.

Since each table has to be managed with a corresponding class for ActiveRecord, I created a base abstract class that the other tables could inherit from and initialise ActiveRecord against...

Wow, I'm explaining this crappily - here is some code instead to illustrate:

abstract class AchieveTargetBase : ActiveRecordBase
    {
        private int _id;
        private Subject _subject;
        private string _comment;
        private int _yeargroup;

        [PrimaryKey]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        [BelongsTo("Subject")]
        public Subject Subject
        {
            get { return _subject; }
            set { _subject = value; }
        }

        [Property(Length=400)]
        public string Comment
        {
            get { return _comment; }
            set { _comment = value; }
        }

        [Property]
        public int YearGroup
        {
            get { return _yeargroup; }
            set { _yeargroup = value; }
        }
    }


And then I do...

[ActiveRecord("Achieve1")]
class Achievement1 : AchieveTargetBase
{
}


And so on, per table, which works fine.

Now the problem I have is with writing classes that I need to use on each table, because I need to reference the class itself. As an example, if I were to write code that retrieves the comment text of selected rows for Achieve1

[ActiveRecord("Achieve1")]
    class Achievement1 : AchieveTargetBase
    {
        public static string[] GetListOfEntries(Subject subj, int year)
        {
            List<string> Entries = new List<string>();

            foreach (Achievement1 x in (Achievement1[])ActiveRecordBase.FindAll(typeof(Achievement1), Expression.Eq("Subject", subj), Expression.Eq("YearGroup", year)))
            {
                Entries.Add(x.Comment);
            }

            string[] ret = Entries.ToArray();
            Array.Sort(ret);
            return ret;
        }
    }


I've tried replacing Achievement1 in the foreach argument with AchieveTargetBase and putting it into the AchieveTargetBase class instead but that just throws up an error (which I expected, to be honest).

Is there any way I can make methods like that apply for each class without having to write it separately for each of the derived classes?

Disclaimer: I'm a n00bish programmer. Please be gentle. (Especially if the answer is dead easy cos it'll just make me feel stupid. Smile | :)


-- modified at 6:02 Friday 17th August, 2007
AnswerRe: Castle ActiveRecord and abstract classes... Pin
Not Active16-Aug-07 9:19
mentorNot Active16-Aug-07 9:19 
AnswerRe: Castle ActiveRecord and abstract classes... Pin
Mark Churchill16-Aug-07 15:46
Mark Churchill16-Aug-07 15:46 
GeneralRe: Castle ActiveRecord and abstract classes... Pin
Xiol3216-Aug-07 23:08
Xiol3216-Aug-07 23:08 
General[SOLVED] Re: Castle ActiveRecord and abstract classes... Pin
Xiol3216-Aug-07 23:58
Xiol3216-Aug-07 23:58 
QuestionDe-smellifying some code... Pin
martin_hughes16-Aug-07 6:56
martin_hughes16-Aug-07 6:56 
AnswerRe: De-smellifying some code... Pin
MidwestLimey16-Aug-07 7:24
professionalMidwestLimey16-Aug-07 7:24 
GeneralRe: De-smellifying some code... Pin
martin_hughes16-Aug-07 12:12
martin_hughes16-Aug-07 12:12 
GeneralRe: De-smellifying some code... Pin
Luc Pattyn16-Aug-07 13:03
sitebuilderLuc Pattyn16-Aug-07 13:03 
GeneralRe: De-smellifying some code... Pin
martin_hughes17-Aug-07 6:50
martin_hughes17-Aug-07 6:50 
GeneralRe: De-smellifying some code... Pin
MidwestLimey16-Aug-07 17:20
professionalMidwestLimey16-Aug-07 17:20 
AnswerRe: De-smellifying some code... Pin
PhilDanger16-Aug-07 8:15
PhilDanger16-Aug-07 8:15 
AnswerRe: De-smellifying some code... Pin
Leslie Sanford16-Aug-07 12:35
Leslie Sanford16-Aug-07 12:35 
Questionanonymous method runs "too many times" Pin
gericooper16-Aug-07 5:53
gericooper16-Aug-07 5:53 
AnswerRe: anonymous method runs &quot;too many times&quot; [modified] Pin
Luc Pattyn16-Aug-07 6:45
sitebuilderLuc Pattyn16-Aug-07 6:45 
GeneralRe: anonymous method runs &quot;too many times&quot; Pin
gericooper16-Aug-07 20:26
gericooper16-Aug-07 20:26 
Questionlayers (?) Pin
tim_gunning16-Aug-07 5:52
tim_gunning16-Aug-07 5:52 
AnswerRe: layers (?) Pin
Mark Churchill16-Aug-07 15:54
Mark Churchill16-Aug-07 15:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.