ISessionFactory InitializeSessionFactory() { var conventions = new IConvention[] { Table.Is(x => x.EntityType.Name.ToLowerInvariant()), // All table names are lower case ForeignKey.EndsWith("Id"), // Foreign key references end with Id DefaultLazy.Always() // Enable Lazy-Loading by default } .Concat(DatabaseConventions.NeverNull()) .ToArray(); var config = Fluently.Configure() .Database(DatabaseConfiguration) .Mappings(m => m.FluentMappings .AddFromAssemblyOf <DatabaseAdapter>() .Conventions.Add(conventions)); nhConfig = config.BuildConfiguration(); sessionFactory = config.BuildSessionFactory(); return(sessionFactory); }
public void DeleteCompany_WithFigure_DeleteCascades(Type figureType) { var company = CreateFakeCompanyWithStock(); AddFakeFigure(company.Stocks.Single(), figureType, myCurrency); var tableName = DatabaseConventions.GetTableName(figureType); string ownerIdColumn; Func <Company, long> GetId; var property = typeof(Company).GetProperty(tableName); if (property != null) { ownerIdColumn = "Company_Id"; GetId = c => c.Id; } else { property = typeof(Stock).GetProperty(tableName); if (property != null) { ownerIdColumn = "Stock_Id"; GetId = c => c.Stocks.Single().Id; } else { throw new NotSupportedException("Don't know how to detect owner"); } } SaveAndVerify(company, tableName, ownerIdColumn, c => c.Id); DeleteAndVerify(company, tableName, ownerIdColumn, c => c.Id); }