Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ORMS: CoolStorage example
using Activa.CoolStorage;
[MapTo("people")]
public class Person : CSObject<Person, Guid>
{
[MapTo("id")]
public abstract Guid Id { get; set; }
[MapTo("name")]
public abstract string Name { get; set; }
[MapTo("email")]
public abstract string Email { get; set; }
}
public class PersonManager
{
public static void Example()
{
// Requires app.config/web.config settings:
// <CoolStorage>
// <add key="Connection" value="CSDataProviderSqlServer,Activa.CoolStorage.SqlServer / database=dev;uid=dev;password=password;server=(local)"/>
// </CoolStorage>
// Save example
Person person = Person.New();
person.Name = "John";
person.Email = "john@aol.com";
person.Save();
// Some examples of loading
Person p = Person.ReadFirst("Name='John'");
CSList<Person> list = Person.List();
int count = list.Count;
// An example of object notation (if Person had an Address object as
// a property)
list = Person.List("Address.Town = 'London'");
// Paging
int page = 1;
int itemsPerPage = 10;
// e.g. (10 * 3) - 10
int start = (itemsPerPage * page) - itemsPerPage;
list = Person.List().Range(start, itemsPerPage);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.