私はFluentNHibernate チュートリアルを完成させようとしてきましたが、コンパイルに問題がありました。チュートリアルに記載されているとおりにすべてを実行し、自分のコードを GitHub のソースと比較したと思いますが、このコードでこの例外が引き続き発生します。
private static void BuildSchema(Configuration config)
{
if (File.Exists(DbFile))
File.Delete(DbFile);
new SchemaExport(config)
.Create(false,true);
}
次から呼び出されます:
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(
SQLiteConfiguration.Standard
.UsingFile("FluentNHTry.db")
)
.Mappings( m=> m.FluentMappings.AddFromAssemblyOf<Program>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
例外は次のとおりです。
NHibernate.MappingException: Association references unmapped class: System.Char
at NHibernate.Cfg.XmlHbmBinding.CollectionBinder.BindCollectionSecondPass(ICollectionPropertiesMapping collectionMapping, Collection model, IDictionary`2 persistentClasses, IDictionary`2 inheritedMetas)
at NHibernate.Cfg.XmlHbmBinding.CollectionBinder.<>c__DisplayClass13.<AddCollectionSecondPass>b__12(IDictionary`2 persistentClasses)
at NHibernate.Cfg.Configuration.SecondPassCompile()
at NHibernate.Cfg.Configuration.GenerateDropSchemaScript(Dialect dialect)
at NHibernate.Tool.hbm2ddl.SchemaExport.Initialize()
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1 scriptAction, Boolean export, Boolean justDrop)
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean export, Boolean justDrop)
at NHibernate.Tool.hbm2ddl.SchemaExport.Create(Boolean script, Boolean export)
at FluentNHTry.Program.BuildSchema(Configuration config) in c:\Users\JMcKenn1\Documents\Visual Studio Projects\FluentNHTry\FluentNHTry\Program.cs:line 105
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()}
そして、私はそれを修正する方法がわかりません。誰かが私が間違っているところを指摘してくれれば、それは素晴らしいことです.
注 - コードがデータベースを作成すると信じているため、データベースを作成していませんが、このエラーがデータベースがないことに関連しているようには見えません。
編集 - 尋ねられたように、マッピングとエンティティ クラスは次のとおりです。
マッピング:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentNHibernate.Mapping;
using FluentNHTry.Entities;
namespace FluentNHTry.Mappings
{
public class EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
Id(x => x.Id);
Map(x => x.FirstName);
Map(x => x.LastName);
References(x => x.Store);
}
}
public class ProductMap : ClassMap<Product>
{
public ProductMap()
{
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Price);
HasManyToMany(x => x.StoresStockedIn)
.Cascade.All()
.Inverse()
.Table("StoreProduct");
}
}
public class StoreMap : ClassMap<Store>
{
public StoreMap()
{
Id(x => x.Id);
Map(x => x.Name);
HasMany(x => x.Name)
.Inverse()
.Cascade.All();
HasManyToMany(x => x.Products)
.Cascade.All()
.Table("StoreProduct");
}
}
}
エンティティ:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FluentNHTry.Entities
{
public class Employee
{
public virtual int Id { get; protected set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual Store Store { get; set; }
}
public class Product
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
public virtual double Price { get; set; }
public virtual IList<Store> StoresStockedIn { get; protected set; }
public Product()
{
StoresStockedIn = new List<Store>();
}
}
public class Store
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
public virtual IList<Product> Products { get; set; }
public virtual IList<Employee> Staff { get; set; }
public Store()
{
Products = new List<Product>();
Staff = new List<Employee>();
}
public virtual void AddProduct(Product product)
{
product.StoresStockedIn.Add(this);
Products.Add(product);
}
public virtual void AddEmployee(Employee employee)
{
employee.Store = this;
Staff.Add(employee);
}
}
}