views:

40

answers:

2

Today I learned this

JavaScriptSerializer ser = new JavaScriptSerializer();
Foo foo = ser.Deserialize<Foo>(jsonSz);

I had to match the class with the json I was pulling from a remote site. It saved me much time that I could just write the class and not worry about processing the data and putting them into the class. I also didn't need to use attributes everywhere. Example here

Is there a lib I can use for T-SQL (which I hope supports MySQL and SQLite) to allow me to write classes like the below and easily do something like

results = doSomething<User>(@"select id WHERE username=? password=?", user, hash(pass));
//results is null or results.id is the only initialize value.
class User
{
    [primary_key]
    long id;
    string username;
    byte[] password;
    DateTime create, lastLogin;
    string? signature; //the only column that is allow to have null.
    //etc
}
class Comment
{
    [primary_key]
    long id;
    User author; //automatically uses user as a reference foreign key
    Comment parent; //may be 0 to stand for root. But all PK start at 1 so does this cause trouble when using foreign keys?
    DateTime post;
    string comment;
}
//I have no idea how a query for a comment with each of its children comment going 5 deep would look like
//I wouldn't mind writing all SQL queries
+2  A: 

What you need is an Object Relational Mapping framework such as NHibernate or Subsonic.

Wikipedia has a good list of ORM frameworks for .NET.

AdamRalph
+1  A: 

Take a look at linq-to-sql, the or mapper that this site run on..

http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

KristoferA - Huagati.com
What do you mean by 'mapper that this site run on'?
acidzombie24
Sorry for the unclear wording. :) StackOverflow (=='this site') uses Linq-to-SQL.
KristoferA - Huagati.com