Search     Login     Register    

Download Documentation Tools News

Community Forum Bugs Requests


FAQ

Table Of Contents


What is NPersist?
What is O/R Mapping?
Does it cost anything to use NPersist?
What license does NPersist come with?
If I use NPersist in my project, will I have to make my project open source?
Where can I download the NPersist framework and source code?
What language is NPersist written in?
Does NPersist support saving .NET objects written in any .NET language?
Which databases and providers does NPersist support?
I see MatsSoft sells an editor...do I need it to use NPersist?
How does NPersist work?
Does NPersist require code generation?
Does NPersist require that my objects inherit any framework class?
Can you show me an example of source code for a persistent object?
Can you show me an example of an XML Mapping File?
How does code for loading/saving an object with NPersist look?


What is NPersist?

NPersist is a .NET persistence framework using Object/Relational Mapping to save - or persist - your .NET objects to a back-end relational database.

Naturally, NPersist will also load your objects back from the database for you, as well as let you delete them and create new ones.

[Top]

What is O/R Mapping?

Object/Relational Mapping is when you specify how objects and their properties map to relational database tables and their columns.

Using the O/R Mapping information, a persistence framework (such as NPersist) can then save and load the values of your objects' properties to and from the columns of the tables in your relational datbase.

In the simplest case, for every class you have a corresponding database table, and for every property a corresponding column. In this case, we have a 1:1 Mapping.

In more complicated situations, however, the mapping will not be quite 1:1, and that is when the term Object/Relational Mapping really starts to apply.

So, a persistence framework is there to load and save your objects and O/R Mapping is what a persistence framework uses to convert the data from what is often a more cumbersome format in the relational database into an object oriented data structure that is more comfortable for the developer to work with.

In a nutshell: The point with a Persistence Framework, such as NPersist, is to make data access easy. The point with Object/Relational Mapping is to make the data easy to work with. Blue
screen of Death.

[Top]

Does it cost anything to use NPersist?

No! Not a dime. Downloading and using NPersist is completely free of charge!

[
Top]

What license does NPersist come with?

NPersist is distributed under the
GNU Lesser General Public License 2.1 (LGPL)

[Top]

If I use NPersist in my project, will I have to make my project open source?

No! LGPL is the milder form of the GPL license which does not force you to open source any of your work that makes use of the NPersist framework.

[
Top]

Where can I download the NPersist framework and source code?

The full download is available as a GotDotNet workspace, at:

http://workspaces.gotdotnet.com/npersist

[Top] [Top]

What language is NPersist written in?

The source code for the NPersist framework is written in Microsoft Visual Basic.NET for the .NET Framework v1.1.

[
Top]

Does NPersist support saving .NET objects written in any .NET language?

Why, certainly.

[
Top]

Which databases and providers does NPersist support?

Currently NPersist supports the following databases and providers:

  • MS SQL Server (Providers: SqlClient And Borland Data Provider)
  • MS Access (Providers: OleDb And Borland Data Provider)
  • Borland Interbase (Providers: Borland Data Provider)

Support for more databases/providers is upcoming.

If you would like to see your favorite database/provider added to the list of supported databases, and you have a bit of experience with the database/provider in question, why not apply for membership at the GotDotNet workspace and contribute your knowledge to the project? Learn more about
holiday villas barcelona locator

[Top]

I see MatsSoft sells an editor...do I need it to use NPersist?

No, you don't need MatsSoft ObjectMapper 2004 or any other tool to use NPersist.

ObjectMapper is a GUI Editor for the NPersist XML files containing the object/relational mapping information relating objects to tables.

While this is a very comfortable way of editing your XML files, and surely something to consider if you work a lot with NPersist, you can of course write your XML files manually in any editor of your choice.

All you need in order to use NPersist to its full capabilities is included in the download from the NPersist GotDotNet Workspace

[Top]

How does NPersist work?

NPersist uses reflection and an XML Mapping File to provide persistence to .NET objects.

You have to specify in the XML Mapping File how your objects map to the tables in your relational database. The NPersist framework can then use reflection to read data in and out of your objects and generate SQL in order to communicate with the database.

[
Top]

Does NPersist require code generation?

No. While you have to make a few modifications to your objects before NPersist can save them to a database, these are minor efforts that certainly don't require any code generator - you can easily code your objects from scratch or update your existing objects manually in your favorite editor!

[
Top]

Does NPersist require that my objects inherit any framework class?

No. It does, however, require that your objects implement two framework interfaces.

The two interfaces are extremely easy and straight-forward to implement, and one of them has a base class implementing it available in the framework. This is so that you can inherit the base class to implement the interfcae in cases where you don't need the single inheritance .NET offers for inheriting any other base class

[
Top]

Can you show me an example of source code for a persistent object?

Sure! Here is the source code, both in C# and Visual Basic.NET versions, for an 'Employee' class implementing the necessary requirements for persistence with NPersist:

NPersist 'Employee' Class Example Code, C#

NPersist 'Employee' Class Example Code, VB.NET

[Top]

Can you show me an example of an XML Mapping File?

Absolutely! Here is the NPersist XML Mapping File for the mapping the 'Employee' class from the example above to the 'tblEmployees' table in a Microsoft SQL Server database.

NPersist 'Employee' Example XML Mapping File

[Top]

How does code for loading/saving an object with NPersist look?

Here's a little code smippet (C# and VB.NET) that shows how we create, fetch, update and delete an instance of the 'Employee' class from the example above using the NPersist framework:


C#

//Create the context manager
Context Context = 
	new Context("C:\MyDOmain.npersist");

//Fetch employee with ID = 1
Employee emp = Context.GetObject(1, GetType(Employee));

//Update the employee
emp.FirstName = "New";
emp.LastName = "Name";

//ask the context manager to save updates to database
Context.PersistAll();

//Dispose the context manager
Context.Dispose();

Visual Basic.NET

'Create the context manager
Dim Context As New Context("C:\MyDOmain.npersist")

'Fetch employee with ID = 1
Dim emp As Employee 

emp = Context.GetObject(1, GetType(Employee))

'Update the employee
emp.FirstName = "New"
emp.LastName = "Name"

'ask the context manager to save updates to database
Context.PersistAll()

'Dispose the context manager
Context.Dispose()

Following is a slightly longer example that shows how we create, fetch, update and delete an instance of the 'Employee' class from the example above using the NPersist framework:

NPersist Example Code, C#

NPersist Example Code, VB.NET

[Top]

Copyright © Mats Helander 2004 | MatsSoft