Estou dando continuidade do curso de C#, fiz a aplicação conforme está no vídeo:
program.cs
using Loja.Infra;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Loja
{
class Program
{
static void Main(string[] args)
{
NHibernateHelper.GeraSchema();
Console.Read();
}
}
}
-----------------------------------------------------
Usuario.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Loja.Entidades
{
public class Usuario
{
public virtual int Id { get; set;}
public virtual string Nome { get; set; }
}
}
-------------------------------------------------
Usuario.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Loja"
namespace="Loja.Entidades">
<class name="Usuario">
<id name="Id">
<generator class="identity" />
</id>
<property name="Nome" />
</class>
</hibernate-mapping>
-------------------------------------------------------------
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MySql5Dialect</property>
<property name="connection.connection_string">
Server=localhost;Database=loja;Uid=root;Pwd=vini1428;
</property>
<property name="show_sql"></property>
</session-factory>
</hibernate-configuration>
--------------------------------------------------------------------
NHibernateHelper.cs
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Loja.Infra
{
public class NHibernateHelper
{
public static Configuration RecuperaConfiguracao()
{
Configuration cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(Assembly.GetExecutingAssembly());
return cfg;
}
public static void GeraSchema()
{
Configuration cfg = RecuperaConfiguracao();
new SchemaExport(cfg).Create(true, true);
}
}
}
Após rodar o projeto aparece o erro:
An unhandled exception of type 'NHibernate.MappingException' occurred in NHibernate.dll
Additional information: Could not compile the mapping document: Loja.Mapeamentos.Usuario.hbm.xml
Em view Detail: O campo NHibernate.MappingException = {"Could not compile the mapping document: Loja.Mapeamentos.Usuario.hbm.xml"}