Created
February 12, 2009 01:07
-
-
Save SamSaffron/62414 to your computer and use it in GitHub Desktop.
AR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// first param is the class, second is the primary key | |
public class Order : ActiveRecord<Order,int> { | |
BelongsTo<Customer> Customer { get; set; } | |
[PrimaryKey(AutoIncrement=true)] | |
public int Id { get; set; } | |
public string Details { get; set; } | |
} | |
[Index("FirstName", "LastName")] | |
[Index("LastName", "FirstName")] | |
public class Customer : ActiveRecord<Customer,int> | |
{ | |
public HasMany<Order> Orders { get; set; } | |
[PrimaryKey(AutoIncrement=true)] | |
public int Id { get; set; } | |
[ColumnInfo(MinLength=4, MaxLength=255, Nullable=false)] | |
public string FirstName { get; set; } | |
[ColumnInfo(MinLength=4, MaxLength=255, Nullable=false)] | |
public string LastName { get; set; } | |
public string Comments { get; set; } | |
} | |
[TestClass] | |
public class TestActiveRecord { | |
public void Demo() | |
{ | |
ActiveRecordSettings.ConnectionProvider = new EseConnectionProvider("c:\\temp\\db"); | |
Customer.Migrate(); | |
Order.Migrate(); | |
var customer = Customer.Build(); | |
customer.FirstName = "bob"; | |
customer.LastName = "doe"; | |
var order = customer.Orders.Build(); | |
order.Details = "This is the first order"; | |
customer.Save(); | |
var customer2 = Customer.Find(customer.Id); | |
Assert.AreEqual(1, customer2.Orders.Count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment