soderlind.no

I code for fun

Neo (.NET Entity Objects)

| 0 comments

Why Neo? Because it is simple and object-oriented:

The following code snipped shows how to load all titles (i.e. books) that were published before a certain date, apply a clearance discount and then save the changes to the database:

IDataStore datastore = new SqlDataStore(" database connection string ");
ObjectContext context = new ObjectContext(datastore);
TitleFactory factory = new TitleFactory(context);
TitleList matchingTitles = factory.Find("PublicationDate < {0}", new DateTime(2003, 1, 1));
foreach(Title title in matchingTitles) {
    title.ApplyClearanceDiscount();
}
context.SaveChanges();

Where ApplyClearanceDiscount() could look like:

public void ApplyClearanceDiscount()
{
    this.Price = this.Price * (1 - GetClearanceDiscount());
}

… from 5 Reasons

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Required fields are marked *.

*


Rodney's 404 Handler Plugin plugged in.