Entity Definitions

These are the Entity definitions for the examples in this section:

    [Entity(KeyScheme = KeyScheme.Identity)]
    public class Author
    {
        [Field(IsPrimaryKey = true)]
        public int ID { get; set; }

        [Field]
        public string Name { get; set; }

        [Reference(typeof(Book), "AuthorID")]
        Book[] Books { get; set; }
    }

    [Entity(KeyScheme = KeyScheme.Identity)]
    public class Book
    {
        [Field(IsPrimaryKey = true)]
        public int ID { get; set; }

        [Field]
        public int AuthorID { get; set; }

        [Field]
        public string Title { get; set; }
    }

Faster Object Creation

ORM uses Reflection to create instances of your Entity classes, and Reflection tends to be slow.  What is especially slow is filling Property values by name.  In an effort to reduce this overhead, ORM allows you to provide an optional static Entity generation proxy that significantly reduces the time required to build Entity instances.  See the documentation on ORM_CreateProxy for more information.

Basic Data Reads

TBD

Reading data with a Reference

Here's an example for inserting and then reading back out entities that use a 1:n reference

// insert an author
var dumas = new Author() { Name = "Alexadre Dumas" };
store.Insert(dumas);

// insert a couple books.
// note that we're inserting the foreign key value
store.Insert(
    new Book()
    {
        AuthorID = dumas.ID,
        Title = "The Count of Monte Cristo"
    });

store.Insert(
    new Book()
    {
        AuthorID = dumas.ID,
        Title = "The Three Musketeers"
    });

// now get the authors back, telling ORM to fill the references
var authors = store.Select<Author>(true);

// at this point you will have 1 Author instance, with the Books property hydrated and containing two Book instances

Last edited May 29, 2013 at 5:18 PM by ctacke, version 5

Comments

No comments yet.