Getting Started
Creating a new mapping class
- Copy the Frog.Orm.dll assembly to the Lib directory of your project.
- Add a reference to the assembly.
- Next, add a new empty class.
- Add public properties to the class, that matches your database schema (column
types and names) like in the example below.
1: [Table]
2: public class User
3: {
4: [PrimaryKey]
5: public long Id { get; set; }
6:
7: [Column]
8: public string Name { get; set; }
9: }
Retrieving data from the database
In order to retrieve data you first create a mapping class, that matches the structure of the data you are trying to fetch. Next, you can instantiate a Repository object that will actually fetch the data. See example below.1: public void Test()
2: {
3: using(var connection = new Connection("<connection string>");)
4: {
5: var repository = new Repository(connection)
6: var users = repository.GetAll<User>();
7:
8: foreach(var user in users)
9: {
10: Console.WriteLine(user.Name);
11: }
12: }
13: }
Naturally you can also perform more complicated queries using a repository. For instance you also want to get the users that meet a certain criteria. See the example below.
1: public void Test()
2: {
3: using(var connection = new Connection("<connection string>");)
4: {
5: var repository = new Repository(connection)
6: var users = repository.GetWhere<User>(Field.And(
7: Field.Equals("Name", "John"),
8: Field.GreaterThan("Age", 45)
9: )
10: );
11:
12: foreach(var user in users)
13: {
14: Console.WriteLine(user.Name);
15: }
16: }
17: }
Storing data in the database
As with retrieving data, you need a mapping class to store data in the database. In most situations you can use the same mapping class that is used when fetching data. You can create a new instance of your object, and provide it as a parameter to the Create or Update method on a Repository object. See example below.1: public void Test()
2: {
3: using(var connection = new Connection("<connection string>"))
4: {
5: var repository = new Repository(connection)
6: var user = new User();
7: user.Name = "Bill Gates";
8:
9: user = repository.Create(user);
10:
11: connection.CommitChanges();
12: }
13: }
