VITA Quick Start - Source Code
File BookEntities.cs - entity definitions
using System;
using System.Collections.Generic;
using Vita.Entities;
namespace BookStore {
public enum BookCategory {
Programming,
Fiction,
Kids,
}
[Entity, ClusteredIndex("CreatedOn,Id")]
public interface IBook {
[PrimaryKey, Auto]
Guid Id { get; set; }
[Auto(AutoType.CreatedOn)]
DateTime CreatedOn {get; set;}
[Size(100), Index]
string Title { get; set; }
[Size(Sizes.Description), Nullable]
string Description { get; set; }
[Unlimited, Nullable]
string Abstract { get; set; }
BookCategory Category { get; set; }
DateTime? PublishedOn { get; set; }
IPublisher Publisher {get; set;}
[ManyToMany(typeof(IBookAuthor))]
IList<IAuthor> Authors {get;}
}
[Entity]
public interface IPublisher {
[PrimaryKey, Auto]
Guid Id { get; set; }
[Size(Sizes.Name), Unique]
string Name { get; set; }
[OrderBy("PublishedOn:DESC")]
IList<IBook> Books { get; }
}
[Entity]
public interface IAuthor {
[PrimaryKey, Auto]
Guid Id { get; set; }
[Size(Sizes.Name)]
string FirstName { get; set; }
[Size(Sizes.Name)]
string LastName { get; set; }
[Unlimited, Nullable]
string Bio { get; set; }
[ManyToMany(typeof(IBookAuthor))]
IList<IBook> Books {get;}
}
[Entity, PrimaryKey("Book,Author"), ClusteredIndex("Book,Author")]
public interface IBookAuthor {
[CascadeDelete]
IBook Book { get; set; }
IAuthor Author { get; set; }
}
File BooksModule.cs - books module
using System;
using System.Collections.Generic;
using Vita.Entities;
namespace BookStore {
public class BooksModule : EntityModule {
public BooksModule(EntityArea area) : base(area, "BooksModule") {
RegisterEntities(typeof(IBook), typeof(IPublisher),
typeof(IAuthor), typeof(IBookAuthor));
}
}
File BooksEntityApp.cs - entity application
using System;
using System.Collections.Generic;
using Vita.Entities;
using Vita.Modules.Logging;
namespace BookStore {
public class BooksEntityApp : EntityApp {
public BooksModule MainModule;
public BooksEntityApp() {
var booksArea = this.AddArea("Books", "books");
MainModule = new BooksModule(booksArea);
var logArea = this.AddArea("Log", "log"); //creating separate schema
var logModule = new ErrorLogModule(logArea);
}
}//class
}
File BookStoreConfig.cs - static initialization class
using System;
using System.Collections.Generic;
using Vita.Entities;
using Vita.Data;
using Vita.Data.MsSql;
namespace BookStore {
public static class BookStoreConfig {
public static BooksEntityApp App {get; private set;}
public static void Configure (string connectionString) {
App = new BooksEntityApp();
App.Init();
var driver = new MsSqlDriver(MsSqlVersion.V2012);
var dbSettings = new DbSettings(driver, MsSqlDriver.DefaultMsSqlDbOptions,
connectionString, modelUpdateMode: DbModelUpdateMode.Always);
App.ConnectTo(dbSettings);
}
}//class
}