|
Home > .NET Object Database > Source Code Example
Source Code Example
Signumsoft .NET Object Database offers a highly transparent and straight forward
API. The following few lines of code demonstrate what you have to do in order to
persist objects on database. No relational database designing is needed.
Mapping happens already on the database with the automatically generated SQL views.
Class Definition
Following you see how to define a persistent class Person:
using Signumsoft.ObjectDatabase;
public
class Person
: ObjectX
{
public
Person(Database database,
Guid objectId)
:
base(database, objectId)
{
}
public
string NameFirst
{
get
{
return GetValue<string>("NameFirst", null);
}
set
{
SetValue("NameFirst", value);
}
}
public
Person[] Friends
{
get
{
return GetValueArray<Person>("Friends");
}
set
{
SetValueArray<Person>("Friends",
value);
}
}
}
Create and Save Objects
Following you see how to create and save the object Person:
Database
database = new Database(Settings.Default.ConnectionString,
true);
Person
max = new Person(database,
Guid.NewGuid());
Select Objects
The following line code shows how to select all persons:
database.SelectObjectList<Person>("SELECT ObjectId
FROM View_Person");
|