FluentFramework
1.0.0
Portefeuille BTC : 3DNnt9KCKcSqFpWw6g5yWPLAnbRqbB8cPR
public class DefaultConnection : IConnectionConfigurer
{
public IPersistenceConfigurer Configuration()
{
return SQLiteConfiguration.Standard.ConnectionString("Data Source=Database.db;Version=3;");
}
}
public partial class App : Application
{
public App()
{
ConnectionDescriptors.Add<DefaultConnection>(true, false, false);
}
}
public class Book : Entity<DefaultConnection>
{
public virtual string Name { get; set; }
public virtual User User { get; set; }
public override bool OnPreInsert()
{
return Name != "maybe a banned word check?"; //cancel
}
public override bool OnPreUpdate()
{
return true;
}
public override bool OnPreDelete()
{
return true;
}
}
public class BookMap : EntityMap<Book, DefaultConnection>
{
public BookMap()
{
Map(x => x.Name).Not.Nullable();
References(x => x.User).Not.Nullable();
}
}
public User GetUser(string username)
{
using (var repository = new Repository<DefaultConnection>())
{
return repository.Query<User>().Where(x => x.Username == username).SingleOrDefault();
}
}
public void AddBook(string bookName, User user)
{
using (var repository = new Repository<DefaultConnection>())
{
repository.Transaction.Begin();
var book = new Book { Name = bookName, User = user };
repository.Add(book);
repository.SaveChanges();
if(!doSomethingWithBook(book))
{
repository.Transaction.Rollback();
}
}
}
Examinez le projet pour voir ce que vous pouvez faire de plus.