开发者

access data in table in .net as in ruby-on-rails

I would li开发者_如何学编程ke to access data in my database in .NET C# as the ActiveRecord does in rails .

As for example if I have a table "tickets" i can create a new entry in my database in a form similar to

ticket_ = Ticket.new

...

ticket_.save

How can i define such a database in .NET ?

Does anyone have a good tutorial about this ?


You did not write anything about the persistence layer you use...

var ticket_ = new Ticket();
...
ticket_.save(); //you can achieve this using extension methods

Extension methods allow you to extend classes without changing them, as long as you only use public members.

public static class EntityExtensions {
    public static void Save(this object entity) {
        var myMapper = MapperFactory.GetMapper();
        myMapper.persist(entity);
    }
    public static void Delete(this object entity) {
        //...
    }
}

More info: http://msdn.microsoft.com/en-us/library/bb383977.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜