Click here to Skip to main content
15,889,034 members
Home / Discussions / C#
   

C#

 
QuestionRichTextBox ZoomFactor Property Pin
Mark F.7-Aug-07 6:35
Mark F.7-Aug-07 6:35 
AnswerRe: RichTextBox ZoomFactor Property Pin
Luc Pattyn7-Aug-07 6:46
sitebuilderLuc Pattyn7-Aug-07 6:46 
GeneralRe: RichTextBox ZoomFactor Property Pin
Mark F.7-Aug-07 6:48
Mark F.7-Aug-07 6:48 
AnswerRe: RichTextBox ZoomFactor Property Pin
Hessam Jalali7-Aug-07 6:52
Hessam Jalali7-Aug-07 6:52 
QuestionLabel text alignment Pin
RussBus7-Aug-07 6:34
RussBus7-Aug-07 6:34 
AnswerRe: Label text alignment Pin
Luc Pattyn7-Aug-07 6:39
sitebuilderLuc Pattyn7-Aug-07 6:39 
GeneralRe: Label text alignment Pin
RussBus7-Aug-07 9:38
RussBus7-Aug-07 9:38 
QuestionDjango type database access Pin
eggie57-Aug-07 5:58
eggie57-Aug-07 5:58 
If you haven't seen the Django web app framework, it's pretty cool.

All DB access code is generated dynamicly -- all you have to do is define the table structures you want. I.E. (python code)

class Person(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)


Which Django would evaluate to:

CREATE TABLE myapp_person (
    "id" serial NOT NULL PRIMARY KEY,
    "first_name" varchar(30) NOT NULL,
    "last_name" varchar(30) NOT NULL
);


To create a new row in the person table, just create a new instance of Person and call save()

p = Person(first_name='Alex', last_name='Egg')
p.save()


To get all the rows/fields from the Person table just call the static method all Persons.objects.all()
It all seems so elegant, so I wanted to try and recreate this using C#.

So I created a class called Model which is a DB Model like the person class above. I also created a Manager class which exposes the static method All to read data.

public class Model
    {
        public Model()
        {
            
            new NotImplementedException();
        }

        public static Manager Objects;

        public void Save()
        {
           
        }

        public void Delete()
        {
        }
        
    }

    public class Manager
    {
        public Manager()
        {
        }
        public  void Get()
        {
            new NotImplementedException();
        }

        public void All()
        {
            new NotImplementedException();
        }
    }


So now I will create my Person object in C#:

public class SentRecord : Model
    {
        public Person(string firstName, string lastName)
        {
            this.FirstName= firstName;
            this.LastName = lastName;  
        }
      
        public string FirstName;
        public string LastName;
        
    }


I figure this this is pretty much the same idea as the python Person class at the top.
Now I create a new instance of my Person model:

Person p=new Person("Alex","Egg");


Now I can save it to the DB by calling:

p.Save();


Now, my question is, how do I go about implementing Model.Save()? I somehow need to get the names of deriving class' public fields. Reflection? So If I just get the table name (I'll hardcode for now) and the People's fields I can generate my SQL insert statement.

Any pointers on how to implement Save()?


/\ |_ E X E GG

AnswerRe: Django type database access Pin
originSH7-Aug-07 6:08
originSH7-Aug-07 6:08 
AnswerRe: Django type database access Pin
Judah Gabriel Himango7-Aug-07 9:11
sponsorJudah Gabriel Himango7-Aug-07 9:11 
QuestionMulti Threading / Invoke Pin
Peterixina7-Aug-07 5:47
Peterixina7-Aug-07 5:47 
AnswerRe: Multi Threading / Invoke Pin
Judah Gabriel Himango7-Aug-07 6:39
sponsorJudah Gabriel Himango7-Aug-07 6:39 
Questionwebsite code generator Pin
Richard Blythe7-Aug-07 4:20
Richard Blythe7-Aug-07 4:20 
AnswerRe: website code generator Pin
leppie7-Aug-07 5:07
leppie7-Aug-07 5:07 
AnswerRe: website code generator Pin
tker7-Aug-07 20:26
tker7-Aug-07 20:26 
GeneralRe: website code generator Pin
Richard Blythe8-Aug-07 5:28
Richard Blythe8-Aug-07 5:28 
Questiontype converting Pin
M.V7-Aug-07 3:57
M.V7-Aug-07 3:57 
AnswerRe: type converting Pin
PhilDanger7-Aug-07 4:05
PhilDanger7-Aug-07 4:05 
AnswerRe: type converting Pin
ednrgc7-Aug-07 4:07
ednrgc7-Aug-07 4:07 
AnswerRe: type converting Pin
il_masacratore7-Aug-07 4:07
il_masacratore7-Aug-07 4:07 
AnswerRe: type converting Pin
lsconyer7-Aug-07 4:26
lsconyer7-Aug-07 4:26 
GeneralRe: type converting Pin
leppie7-Aug-07 5:08
leppie7-Aug-07 5:08 
GeneralRe: type converting Pin
Judah Gabriel Himango7-Aug-07 5:14
sponsorJudah Gabriel Himango7-Aug-07 5:14 
GeneralRe: type converting Pin
Luc Pattyn7-Aug-07 5:51
sitebuilderLuc Pattyn7-Aug-07 5:51 
GeneralRe: type converting Pin
lsconyer7-Aug-07 6:48
lsconyer7-Aug-07 6:48 

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.