When using nHibernate, which creates class files?
I was under the impression that when using nHibernate after generating xml files etc. all plumbing for basic CRUD operations is done for you along with ie class files
public class Employee
{
public virtual string Name {get; set; }
}
But I must be wrong here because it looks like nothing is being generated or is it not being generated internally when the session / config builds on the first page load?
a source to share
We create the class files first, then the mapping and then we create the db.
Using display attributes directly makes this style (IMO simpler) The code looks something like this:
public class Base {
[Id(..., Column="{{Id.Column}}")]
[AttributeIdentifier(Name="Id.Column", Value="ID")] // Default value
public int Id { ... }
}
[AttributeIdentifier(Name="Id.Column", Value="SUB_ID")]
[Class] public class MappedSubClass : Base { }
I think the generated db model is a little different from what it would be if I started with the db design, but I'm happy with the result.
Just make sure lazy loading works if you are nesting many classes within each other.
a source to share
I don't believe nHibernate will generate classes for you, but you can use a tool like CodeSmith or the next version of LLBLGen to generate them for you.
Check out the "Helpful Tools" section on the dormant website for some tools that might be ... useful. Some of these will generate both mapping files and class files. You can give one of these a try and only take the class files as the basis for your classes.
a source to share
There is a tool for generating classes (only I think, I think), but I recommend writing the classes yourself. These are your domain classes and you should take special care of them. It doesn't look like a typed recordset or something that's only used for db communication.
On the other hand, a tool that creates the db schema is recommended .
a source to share