Wednesday, November 15, 2006

ActiveRecord in .Net

I'm using ActiveRecord in .Net for a school project. And it's making db interaction somewhat bearable. Coming from a Hibernate/ActiveRecord background, this is a breath of fresh air. Never been a fan of the data-mapper/set and stored proc that MS is so up on. Thanks to the Castle (http://castleproject.org/) guys for putting this together, it's very simple to get up and running and I found it _far_ easier to understand their tutorial than any of the NHibernate ones. Their blog app is a piece of cake to understand and runs out of the box (granted you have have a "test" db created).

The biggest issue I had was connecting to SQLServer Express 2005. Here's the connection string I ended up using:

Server=127.0.0.1,1433;Database=patstracks;Integrated Security=SSPI


ActiveRecord really makes it easy to decorate POCOs using attributes:

[ActiveRecord("[Client]")]

public class Client : ActiveRecordBase{
...
[PrimaryKey]

public int Id

{

get { return id; }

set { id = value; }



}
...
public static Client[] FindByNameLike(string name)

{

return (Client[])Client.FindAll(typeof(Client), new Order[] {Order.Asc("Name") }, new ICriterion[] { Expression.Like("Name", name+"%")});



}
...
}

No comments: