After a couple days of tinkering around I was able to get
NHibernate.Mapping.Attributes (2.1 GA) to work. Does anyone know why I
need to explicitly specify the Class name or the type of the ID in the
attributes? It is smart enough to figure out the names and types of
the properties without explicitly setting them, but can't pick up the
class name or id type for some reason.
I've supplied the working bits of code below...maybe there is
something I am missing:
==================================================================
User Class (located in "MyProject.Core" assembly,
"MyProject.Core.Domain" namespace)
==================================================================
[Serializable()]
[Class(Name="User", Table="tw_users")]
public class User
{
[Id(UnsavedValue="0", Type="int"), Generator(Class = "native")]
public virtual int UserId { get; set; }
[Property(Length = 50, NotNull = true)]
public virtual string Name { get; set; }
[Property(Length = 128, NotNull = true, Unique = true)]
public virtual string Email { get; set; }
[Property(Length = 40, NotNull = true)]
public virtual string Password { get; set; }
[Property(NotNull = true)]
public virtual bool Approved { get; set; }
[Property(NotNull = true)]
public virtual DateTime CreatedOn { get; set; }
}
=======================================
Session Helper (located in MyProject.Data assembly)
=======================================
public sealed class NHibernateSessionManager
{
private static Configuration config = null;
private static ISessionFactory sessionFactory = null;
static NHibernateSessionManager()
{
if (config == null)
{
using (MemoryStream stream = new MemoryStream())
{
HbmSerializer.Default.HbmNamespace =
"MyProject.Core.Domain";
HbmSerializer.Default.HbmAssembly =
"MyProject.Core";
HbmSerializer.Default.Validate = true;
HbmSerializer.Default.Serialize(stream,
typeof
(Tectonic.Core.Domain.User).Assembly);
stream.Position = 0;
config = new
Configuration().Configure();
config.AddInputStream(stream,
"Domain.hbm.xml");
sessionFactory =
config.BuildSessionFactory();
}
}
}
public static ISession OpenSession()
{
return sessionFactory.OpenSession();
}
public static IStatelessSession OpenStatelessSession()
{
return sessionFactory.OpenStatelessSession();
}
// Remove from release -- completely destroys and rebuilds db
from
domain model
public static void BuildDb()
{
new
NHibernate.Tool.hbm2ddl.SchemaExport(config).Execute(false,
true, false);
}
}
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.