KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm sure there is something simple I've not done but I'm trying to get Fluent NHibernate to work with Sqlite on my machine. I used NuGet to download fluent nhibernate and added the following entity and mapping: public class Customer { public virtual string CustomerCode { get; set; } public virtual string Name { get; set; } } public class CustomerMap : ClassMap<Customer> { public CustomerMap () { Id(x => x.CustomerCode); Map(x => x.Name); Table("tblCustomer"); } } Then following the getting started with fluent guide I added the following code to a Windows Command project: class Program { static void Main(string[] args) { var sessionFactory = CreateSessionFactory(); using (var session = sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { var customer = new Customer { CustomerCode = "123", Name = "Bob" }; session.SaveOrUpdate(customer); transaction.Commit(); } } } private static ISessionFactory CreateSessionFactory() { return Fluently.Configure() .Database( SQLiteConfiguration.Standard .UsingFile("firstProject.db") ) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>()) .ExposeConfiguration(BuildSchema) .BuildSessionFactory(); } private static void BuildSchema(Configuration config) { // delete the existing db on each run if (File.Exists("firstProject.db")) File.Delete("firstProject.db"); // this NHibernate tool takes a configuration (with mapping info in) // and exports a database schema from it new SchemaExport(config) .Create(false, true); } } F
Tags (comma-separated)
Save Edits
Cancel