【问题标题】:SQL <-> Class (De)Serializer?SQL <-> 类(反)序列化器?
【发布时间】:2009-12-19 11:06:48
【问题描述】:

今天我学到了这个

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

我必须将类与从远程站点提取的 json 进行匹配。它节省了我很多时间,我可以只编写类而不用担心处理数据并将它们放入类中。我也不需要到处使用属性。 Example here

是否有一个我可以用于 T-SQL 的库(我希望它支持 MySQL 和 SQLite),以允许我编写如下所示的类并轻松执行类似的操作

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

【问题讨论】:

    标签: c# .net sql reflection ado.net


    【解决方案1】:

    您需要一个对象关系映射框架,例如 NHibernate 或 Subsonic。

    维基百科有一个很好的list of ORM frameworks for .NET

    【讨论】:

      【解决方案2】:

      看看 linq-to-sql,这个站点运行的或映射器..

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

      【讨论】:

      • 您所说的“运行此站点的映射器”是什么意思?
      • 抱歉措辞不清楚。 :) StackOverflow (=='this site') 使用 Linq-to-SQL。
      猜你喜欢
      • 2016-05-14
      • 2013-10-12
      • 1970-01-01
      • 2013-05-30
      • 1970-01-01
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多