首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQL <->类(反)序列化程序?

SQL <->类(反)序列化程序?
EN

Stack Overflow用户
提问于 2009-12-19 19:06:48
回答 2查看 90关注 0票数 0

今天我学到了这个

代码语言:javascript
复制
JavaScriptSerializer ser = new JavaScriptSerializer();
Foo foo = ser.Deserialize<Foo>(jsonSz);

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

有没有一个库可以用于T-SQL (我希望它支持MySQL和SQLite),让我可以像下面这样编写类,并轻松地执行以下操作

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-12-19 19:14:18

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

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

票数 2
EN

Stack Overflow用户

发布于 2009-12-19 19:19:05

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1932622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档