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; }
    }

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 Sep 7, 2012 at 9:40 PM by ctacke, version 2

Comments

No comments yet.