A Quick Start
Class
definition example – used in this tutorial.
public class UsersGroup
{
[Index]
public string
Name { get; set;
}
public BasicUser[]
Users { get; set;
}
[Index]
public PaidUser
Creator { get; set;
}
}
Supported
attributes:
[Index] – Indicates the field or property that should be
indexed
[Ignore] – Indicates the field or property that should
not be stored in the database
Open database
The
connection string contains all the required parameters to establish a
connection to the server.
The
connection string has the following form:
server=ServerName;database=DatabaseName;user=UserName;password=UserPassword;options=SomeOptions.
(For
more details, see the Setting up Eloquera Server Security Chapter.)
Where:
·
ServerName is a network name of the server
holding Eloquera
·
DatabaseName is the database name on that server
·
UserName is the user name
·
UserPassword is the password for authentication
on that server.
The
options parameter is not compulsory and is currently ignored.
Use the
following to connect from the client:
DB db = new DB("server=localhost;password=pwd;options=none;");
Use the
following to run in desktop mode
DB db = new DB("server=(local);password=pwd;options=none;");
In desktop mode, make sure that the Eloquera server is not running as
a service.
Use
below commands to perform the following tasks:
|
Task |
Command |
Remarks |
|
Create a new database |
db.CreateDatabase("MyDatabaseName"); |
Please note that CreateDatabase does not open database. |
|
Open existing database |
db.OpenDatabase("MyDatabaseName"); |
|
|
Store (or update) object |
db.Store(new Book()); |
|
|
Query |
SELECT [SKIP count][TOP count] TypeName [WHERE {Expression [AND|OR] }[..n]] [ORDER BY
{Expression}[,] [ASC|DESC]}[..n]] var books =
db.ExecuteQuery("SELECT UserGroup WHERE Name = 'Swimmers'"); foreach(var book in books) { … } |
General Query Syntax. Returns all objects that meet the conditions of the query. |
|
Delete object |
var book =
db.ExecuteScalar("SELECT UserGroup WHERE Name = 'Swimmers'"); db.Delete(book); |
Deletes an object that was retrieved from the database. |