SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : Microsoft .NET :

Previous DiscussionNext Discussion
 Persist object to a database?

Ok, I was talking to a colleague of mine, and this conversation evolved from Stored Procedures into object persistence.

My colleague (who is EXTREMELY knowledgeable) is a Java guy, and I'm more of a .NET guy (but I'm learning several different languages).

Anyway, I was asking him recently about using stored procedures in a project, and he told me that using stored procedures is no longer a best practice, and that a "persistence framework" is now a best practice (something like NHibernate).

My thinking at that point was this "persistence" he spoke of was something akin to the way someone can update a database with ADO.NET, like the following (some code excluded for brevity):

// #########################
// UPDATE.
// #########################
DataRow targetRow = dataTable.Rows[index];
Application.DoEvents();
targetRow.BeginEdit();
targetRow["MyField"] = txtSomeText.Text;
targetRow.EndEdit();
DataSet DataSetChanged = DataSet.GetChanges(DataRowState.Modified);
DS.Merge(DataSetChanged);
DataAdapter.Update(DS, "TableName");
DS.AcceptChanges();

Apparently, according to my colleague, this is not the case.

He provided me the following (it's in Java):

EntityManager em;

public void createCustomers()
{
Customer c = new Customer();
c.setCustomerID(1);
c.setFirstName("John");
c.setLastName("Doe");
em.persist(c);
}

Then to load a customer you would do this:

EntityManager em;

public Customer getCustomer(int id)
{
Customer c = em.find(Customer.class, new Integer(id));
return c;
}

The plumbing is handled by the framework, and no explicit DB IO occurs.

He followed that up with:

The call to EntityManager.persist(Object) stores the object in the DB. The call to EntityManager.find(Class, Key) retrieves it. So nothing in particular happens when the object is destructed - just when you make those persistence calls. The persistence framework builds a table on the back end that looks a lot like the object. Classname = tablename, attributeNames = rowNames, etc.

My question to him at that point was:

Ah, so it still hits a DB, it just does it in a different way?

To which he responded:
Yes, it totally encapsulates DB stuff. All you have to do is create an object and tell it to persist. Everything else is done and you never see it. It's like your objects know how to store themselves.

-------------

So my question is this: Is there something like this in .NET (preferably C#)? If so, could someone point me to an example? I've got a couple of projects written down, and I want to start working on them, and I'd like to try this as an experiment.

Any help would be greatly appreciated.

Started By Monte on Jun 8, 2010 at 10:14:46 AM

4 Response(s) | Reply

View All Replies
matspca on Feb 2, 2012 at 8:44:50 PM

Try the World's fastest, most scalable pure C# database system, http://www.VelocityDB.com

It is also easy to use, with a rich set of API and uses 64 bit object identifiers.


View All Replies

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2000 InsideDHTML.com, LLC. All rights reserved.