Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Always perform your INSERT/UPDATE inside a transaction. Here's a working example using SQLite:</p> <pre><code>using System; using System.Data; using System.IO; using FluentNHibernate.Cfg; using FluentNHibernate.Cfg.Db; using FluentNHibernate.Mapping; using NHibernate; class Program { static void Main(string[] args) { if (File.Exists("data.db3")) { File.Delete("data.db3"); } using (var factory = CreateSessionFactory()) { // Create schema and insert sample data using (var connection = factory.ConnectionProvider.GetConnection()) { ExecuteQuery("create table users(usr_id integer primary key, other_id int, usr_name string)", connection); } using (var session = factory.OpenSession()) using (var tx = session.BeginTransaction()) { User u1 = new User() { Name = "User1" }; User u2 = new User() { Name = "User2" }; u1.Other = u2; u2.Other = u1; session.Save(u1); tx.Commit(); } // Verify database state after inserts with ADO.NET using (var connection = factory.ConnectionProvider.GetConnection()) using (var command = connection.CreateCommand()) { command.CommandText = "select usr_id, other_id, usr_name from users"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { Console.WriteLine("usr_id: {0}, other_id: {1}, usr_name: {2}", reader.GetInt32(0), reader.GetInt32(1), reader.GetString(2)); } } } } } private static ISessionFactory CreateSessionFactory() { return Fluently.Configure() .Database( SQLiteConfiguration.Standard.UsingFile("data.db3").ShowSql() ) .Mappings( m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;Program&gt;() ).BuildSessionFactory(); } static void ExecuteQuery(string sql, IDbConnection connection) { using (var command = connection.CreateCommand()) { command.CommandText = sql; command.ExecuteNonQuery(); } } } public class User { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual User Other { get; set; } } public class UserMap : ClassMap&lt;User&gt; { public UserMap() { WithTable("users"); Id(x =&gt; x.Id, "usr_id"); Map(x =&gt; x.Name, "usr_name"); References(x =&gt; x.Other) .ColumnName("other_id") .Cascade.All(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload